Skip to content

Commit 897c973

Browse files
feat(api): manual updates
1 parent a947c6f commit 897c973

6 files changed

Lines changed: 137 additions & 4 deletions

File tree

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 14
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/alchemyst-ai%2Falchemyst-ai-sdk-a172a1ab25e5f79a0b9c189123a168fc9b852105596af4c216a873c4bdd71924.yml
3-
openapi_spec_hash: f12704fa7448d06662d000d3b2b17c86
1+
configured_endpoints: 15
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/alchemyst-ai%2Falchemyst-ai-sdk-27588c5bd8fa58baa7b2e6deb77ec14fc3fe39915dd9e304843ab4a993a9fe84.yml
3+
openapi_spec_hash: 3e1789cdc48121d97f702ad12c77bfb3
44
config_hash: 32e700129a8eaba38674e583e3d39e2b

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ Methods:
4343
Types:
4444

4545
- <code><a href="./src/resources/v1/context/memory.ts">MemoryUpdateResponse</a></code>
46+
- <code><a href="./src/resources/v1/context/memory.ts">MemoryAddResponse</a></code>
4647

4748
Methods:
4849

4950
- <code title="post /api/v1/context/memory/update">client.v1.context.memory.<a href="./src/resources/v1/context/memory.ts">update</a>({ ...params }) -> MemoryUpdateResponse</code>
5051
- <code title="post /api/v1/context/memory/delete">client.v1.context.memory.<a href="./src/resources/v1/context/memory.ts">delete</a>({ ...params }) -> void</code>
52+
- <code title="post /api/v1/context/memory/add">client.v1.context.memory.<a href="./src/resources/v1/context/memory.ts">add</a>({ ...params }) -> MemoryAddResponse</code>
5153

5254
### AddAsync
5355

src/resources/v1/context/context.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
import { APIResource } from '../../../core/resource';
44
import * as MemoryAPI from './memory';
5-
import { Memory, MemoryDeleteParams, MemoryUpdateParams, MemoryUpdateResponse } from './memory';
5+
import {
6+
Memory,
7+
MemoryAddParams,
8+
MemoryAddResponse,
9+
MemoryDeleteParams,
10+
MemoryUpdateParams,
11+
MemoryUpdateResponse,
12+
} from './memory';
613
import * as TracesAPI from './traces';
714
import { TraceDeleteResponse, TraceListParams, TraceListResponse, Traces } from './traces';
815
import * as ViewAPI from './view';
@@ -304,8 +311,10 @@ export declare namespace Context {
304311
export {
305312
Memory as Memory,
306313
type MemoryUpdateResponse as MemoryUpdateResponse,
314+
type MemoryAddResponse as MemoryAddResponse,
307315
type MemoryUpdateParams as MemoryUpdateParams,
308316
type MemoryDeleteParams as MemoryDeleteParams,
317+
type MemoryAddParams as MemoryAddParams,
309318
};
310319

311320
export {

src/resources/v1/context/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ export {
1818
export {
1919
Memory,
2020
type MemoryUpdateResponse,
21+
type MemoryAddResponse,
2122
type MemoryUpdateParams,
2223
type MemoryDeleteParams,
24+
type MemoryAddParams,
2325
} from './memory';
2426
export { Traces, type TraceListResponse, type TraceDeleteResponse, type TraceListParams } from './traces';
2527
export {

src/resources/v1/context/memory.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ export class Memory extends APIResource {
5757
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
5858
});
5959
}
60+
61+
/**
62+
* This endpoint adds memory (chat history) as context.
63+
*
64+
* @example
65+
* ```ts
66+
* const response = await client.v1.context.memory.add({
67+
* contents: [
68+
* {
69+
* content:
70+
* 'Customer asked about pricing for the Scale plan.',
71+
* },
72+
* ],
73+
* sessionId: 'support-thread-TCK-1234',
74+
* });
75+
* ```
76+
*/
77+
add(body: MemoryAddParams, options?: RequestOptions): APIPromise<MemoryAddResponse> {
78+
return this._client.post('/api/v1/context/memory/add', { body, ...options });
79+
}
6080
}
6181

6282
export interface MemoryUpdateResponse {
@@ -67,6 +87,14 @@ export interface MemoryUpdateResponse {
6787
updated_entries: number;
6888
}
6989

90+
export interface MemoryAddResponse {
91+
context_id: string;
92+
93+
success: boolean;
94+
95+
processed_documents?: number;
96+
}
97+
7098
export interface MemoryUpdateParams {
7199
/**
72100
* Array of updated content objects
@@ -135,10 +163,73 @@ export interface MemoryDeleteParams {
135163
user_id?: string | null;
136164
}
137165

166+
export interface MemoryAddParams {
167+
/**
168+
* Array of content objects. Each object must contain at least the 'content' field.
169+
* Additional properties are allowed.
170+
*/
171+
contents: Array<MemoryAddParams.Content>;
172+
173+
/**
174+
* The ID of the session
175+
*/
176+
sessionId: string;
177+
178+
/**
179+
* Optional metadata for the memory context. Defaults to ["default"] if not
180+
* provided.
181+
*/
182+
metadata?: MemoryAddParams.Metadata;
183+
}
184+
185+
export namespace MemoryAddParams {
186+
export interface Content {
187+
/**
188+
* The content of the memory message
189+
*/
190+
content: string;
191+
192+
/**
193+
* Additional metadata for the message (optional)
194+
*/
195+
metadata?: Content.Metadata;
196+
197+
[k: string]: unknown;
198+
}
199+
200+
export namespace Content {
201+
/**
202+
* Additional metadata for the message (optional)
203+
*/
204+
export interface Metadata {
205+
/**
206+
* Unique message ID
207+
*/
208+
messageId?: string;
209+
}
210+
}
211+
212+
/**
213+
* Optional metadata for the memory context. Defaults to ["default"] if not
214+
* provided.
215+
*/
216+
export interface Metadata {
217+
/**
218+
* Optional group names for the memory context. Defaults to ["default"] if not
219+
* provided.
220+
*/
221+
groupName?: Array<string>;
222+
223+
[k: string]: unknown;
224+
}
225+
}
226+
138227
export declare namespace Memory {
139228
export {
140229
type MemoryUpdateResponse as MemoryUpdateResponse,
230+
type MemoryAddResponse as MemoryAddResponse,
141231
type MemoryUpdateParams as MemoryUpdateParams,
142232
type MemoryDeleteParams as MemoryDeleteParams,
233+
type MemoryAddParams as MemoryAddParams,
143234
};
144235
}

tests/api-resources/v1/context/memory.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,33 @@ describe('resource memory', () => {
7171
user_id: 'user_id',
7272
});
7373
});
74+
75+
// Prism tests are disabled
76+
test.skip('add: only required params', async () => {
77+
const responsePromise = client.v1.context.memory.add({
78+
contents: [{ content: 'Customer asked about pricing for the Scale plan.' }],
79+
sessionId: 'support-thread-TCK-1234',
80+
});
81+
const rawResponse = await responsePromise.asResponse();
82+
expect(rawResponse).toBeInstanceOf(Response);
83+
const response = await responsePromise;
84+
expect(response).not.toBeInstanceOf(Response);
85+
const dataAndResponse = await responsePromise.withResponse();
86+
expect(dataAndResponse.data).toBe(response);
87+
expect(dataAndResponse.response).toBe(rawResponse);
88+
});
89+
90+
// Prism tests are disabled
91+
test.skip('add: required and optional params', async () => {
92+
const response = await client.v1.context.memory.add({
93+
contents: [
94+
{
95+
content: 'Customer asked about pricing for the Scale plan.',
96+
metadata: { messageId: 'messageId' },
97+
},
98+
],
99+
sessionId: 'support-thread-TCK-1234',
100+
metadata: { groupName: ['string'] },
101+
});
102+
});
74103
});

0 commit comments

Comments
 (0)