samsar-js 0.48.5 → 0.48.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist/index.d.ts +37 -2
- package/dist/index.js +26 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -115,6 +115,21 @@ const assistant = await samsar.createAssistantCompletion({
|
|
|
115
115
|
});
|
|
116
116
|
console.log(assistant.data.output_text);
|
|
117
117
|
|
|
118
|
+
// Generate an image in the assistant response using the OpenAI-compatible image_generation tool
|
|
119
|
+
const assistantImage = await samsar.createAssistantCompletion({
|
|
120
|
+
session_id: videoFromImages.data.session_id ?? videoFromImages.data.request_id!,
|
|
121
|
+
input: 'Create a clean launch poster image for this session.',
|
|
122
|
+
tools: [{ type: 'image_generation', size: '1024x1024', quality: 'high' }],
|
|
123
|
+
tool_choice: { type: 'image_generation' },
|
|
124
|
+
});
|
|
125
|
+
const generatedImage = assistantImage.data.output?.find(
|
|
126
|
+
(item) => item.type === 'image_generation_call' && typeof item.result === 'string',
|
|
127
|
+
);
|
|
128
|
+
console.log(generatedImage?.result); // base64 image payload
|
|
129
|
+
|
|
130
|
+
// Continue the same multimodal assistant thread by reusing the same session_id.
|
|
131
|
+
// Samsar preserves the underlying OpenAI response chain for follow-up image edits.
|
|
132
|
+
|
|
118
133
|
// Create embeddings from a JSON array
|
|
119
134
|
const embedding = await samsar.createEmbedding({
|
|
120
135
|
name: 'listings',
|
|
@@ -277,6 +292,14 @@ const externalUser = {
|
|
|
277
292
|
const externalSession = await platform.createExternalUserSession(externalUser);
|
|
278
293
|
console.log(externalSession.data.remainingCredits, externalSession.data.external_api_key);
|
|
279
294
|
|
|
295
|
+
// Store an external-user-specific assistant prompt
|
|
296
|
+
await platform.setExternalAssistantSystemPrompt(
|
|
297
|
+
{
|
|
298
|
+
system_prompt: 'You are the storefront assistant for this creator. Keep answers short, commercial, and visually aware.',
|
|
299
|
+
},
|
|
300
|
+
externalUser,
|
|
301
|
+
);
|
|
302
|
+
|
|
280
303
|
// Create a render attributed to that external user
|
|
281
304
|
const externalRender = await platform.createExternalVideoFromText(externalUser, {
|
|
282
305
|
prompt: 'A sleek teaser for a futuristic running shoe',
|
|
@@ -286,6 +309,18 @@ const externalRender = await platform.createExternalVideoFromText(externalUser,
|
|
|
286
309
|
enable_subtitles: true,
|
|
287
310
|
});
|
|
288
311
|
|
|
312
|
+
// Run an assistant completion against one of that external user's sessions.
|
|
313
|
+
// Credits are deducted from the external user, while the owning Samsar account model config is used internally.
|
|
314
|
+
const externalAssistant = await platform.createExternalAssistantCompletion(
|
|
315
|
+
{
|
|
316
|
+
session_id: externalRender.data.request_id,
|
|
317
|
+
input: 'Write a product caption for this video and suggest a headline.',
|
|
318
|
+
max_output_tokens: 250,
|
|
319
|
+
},
|
|
320
|
+
externalUser,
|
|
321
|
+
);
|
|
322
|
+
console.log(externalAssistant.data.output_text);
|
|
323
|
+
|
|
289
324
|
// Fetch their external library
|
|
290
325
|
const library = await platform.listExternalUserRequests(externalUser, { limit: 12 });
|
|
291
326
|
console.log(library.data.requests.length);
|
|
@@ -311,6 +346,9 @@ const verified = await platform.verifyClientSession({
|
|
|
311
346
|
const externalClient = new SamsarClient({
|
|
312
347
|
apiKey: verified.data.authToken!,
|
|
313
348
|
});
|
|
349
|
+
await externalClient.setExternalAssistantSystemPrompt({
|
|
350
|
+
system_prompt: 'You are my personal launch assistant. Stay concise and actionable.',
|
|
351
|
+
});
|
|
314
352
|
const externalLibrary = await externalClient.listExternalUserRequests();
|
|
315
353
|
console.log(externalLibrary.data.requests.map((request) => request.request_id));
|
|
316
354
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -316,6 +316,22 @@ export interface AssistantReasoningConfig {
|
|
|
316
316
|
effort?: 'low' | 'medium' | 'high' | string;
|
|
317
317
|
[key: string]: unknown;
|
|
318
318
|
}
|
|
319
|
+
export interface AssistantImageGenerationTool {
|
|
320
|
+
type: 'image_generation';
|
|
321
|
+
size?: string;
|
|
322
|
+
quality?: 'auto' | 'low' | 'medium' | 'high' | string;
|
|
323
|
+
format?: 'png' | 'jpeg' | 'webp' | string;
|
|
324
|
+
background?: 'auto' | 'transparent' | 'opaque' | string;
|
|
325
|
+
compression?: number;
|
|
326
|
+
partial_images?: number;
|
|
327
|
+
action?: 'auto' | 'generate' | 'edit' | string;
|
|
328
|
+
[key: string]: unknown;
|
|
329
|
+
}
|
|
330
|
+
export type AssistantToolDefinition = AssistantImageGenerationTool | Record<string, unknown>;
|
|
331
|
+
export type AssistantToolChoice = 'auto' | 'none' | 'required' | {
|
|
332
|
+
type?: string;
|
|
333
|
+
[key: string]: unknown;
|
|
334
|
+
} | Record<string, unknown>;
|
|
319
335
|
export interface AssistantSetSystemPromptRequest {
|
|
320
336
|
system_prompt?: string | null;
|
|
321
337
|
systemPrompt?: string | null;
|
|
@@ -332,6 +348,8 @@ export interface AssistantCompletionRequest {
|
|
|
332
348
|
session_id?: string;
|
|
333
349
|
sessionId?: string;
|
|
334
350
|
id?: string;
|
|
351
|
+
previous_response_id?: string;
|
|
352
|
+
previousResponseId?: string;
|
|
335
353
|
input?: string | AssistantInputMessage | AssistantInputMessage[] | AssistantInputContentItem[];
|
|
336
354
|
message?: string | AssistantInputMessage | AssistantInputMessage[] | AssistantInputContentItem[];
|
|
337
355
|
messages?: AssistantInputMessage[];
|
|
@@ -343,8 +361,8 @@ export interface AssistantCompletionRequest {
|
|
|
343
361
|
metadata?: Record<string, unknown>;
|
|
344
362
|
user?: string;
|
|
345
363
|
text?: Record<string, unknown>;
|
|
346
|
-
tools?:
|
|
347
|
-
tool_choice?:
|
|
364
|
+
tools?: AssistantToolDefinition[];
|
|
365
|
+
tool_choice?: AssistantToolChoice;
|
|
348
366
|
parallel_tool_calls?: boolean;
|
|
349
367
|
reasoning?: AssistantReasoningConfig;
|
|
350
368
|
reasoning_effort?: 'low' | 'medium' | 'high' | string;
|
|
@@ -361,6 +379,9 @@ export interface AssistantResponseOutputItem {
|
|
|
361
379
|
type?: string;
|
|
362
380
|
role?: string;
|
|
363
381
|
content?: AssistantResponseContentItem[];
|
|
382
|
+
status?: string;
|
|
383
|
+
revised_prompt?: string;
|
|
384
|
+
result?: string;
|
|
364
385
|
[key: string]: unknown;
|
|
365
386
|
}
|
|
366
387
|
export interface AssistantCompletionResponse {
|
|
@@ -1041,6 +1062,10 @@ export interface ExternalCreateLoginTokenResponse extends CreateLoginTokenRespon
|
|
|
1041
1062
|
external_user?: ExternalUserSummary | null;
|
|
1042
1063
|
externalUser?: ExternalUserSummary | null;
|
|
1043
1064
|
}
|
|
1065
|
+
export interface ExternalAssistantSetSystemPromptResponse extends AssistantSetSystemPromptResponse {
|
|
1066
|
+
external_user?: ExternalUserSummary | null;
|
|
1067
|
+
externalUser?: ExternalUserSummary | null;
|
|
1068
|
+
}
|
|
1044
1069
|
export interface VerifyClientSessionInput {
|
|
1045
1070
|
loginToken?: string;
|
|
1046
1071
|
authToken?: string;
|
|
@@ -1210,6 +1235,16 @@ export declare class SamsarClient {
|
|
|
1210
1235
|
createExternalUserLoginToken(externalUser?: ExternalUserIdentity | null, options?: ({
|
|
1211
1236
|
redirect?: string;
|
|
1212
1237
|
} & SamsarRequestOptions)): Promise<SamsarResult<ExternalCreateLoginTokenResponse>>;
|
|
1238
|
+
/**
|
|
1239
|
+
* Store or clear the external user’s assistant system prompt.
|
|
1240
|
+
* When set, it overrides the owning account prompt for future assistant requests from that external user.
|
|
1241
|
+
*/
|
|
1242
|
+
setExternalAssistantSystemPrompt(payload: AssistantSetSystemPromptRequest, externalUser?: ExternalUserIdentity | null, options?: SamsarRequestOptions): Promise<SamsarResult<ExternalAssistantSetSystemPromptResponse>>;
|
|
1243
|
+
/**
|
|
1244
|
+
* Create an assistant completion scoped to an external user while billing that external user's credit balance.
|
|
1245
|
+
* The owning Samsar account's configured assistant model is used internally.
|
|
1246
|
+
*/
|
|
1247
|
+
createExternalAssistantCompletion(payload: AssistantCompletionRequest, externalUser?: ExternalUserIdentity | null, options?: SamsarRequestOptions): Promise<SamsarResult<AssistantCompletionResponse>>;
|
|
1213
1248
|
/**
|
|
1214
1249
|
* Translate an existing video session into a new language.
|
|
1215
1250
|
* Creates a new session_id and queues generation steps for lip sync + transcription + video render.
|
package/dist/index.js
CHANGED
|
@@ -128,6 +128,32 @@ export class SamsarClient {
|
|
|
128
128
|
}
|
|
129
129
|
return this.post('external_users/create_login_token', body, options);
|
|
130
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Store or clear the external user’s assistant system prompt.
|
|
133
|
+
* When set, it overrides the owning account prompt for future assistant requests from that external user.
|
|
134
|
+
*/
|
|
135
|
+
async setExternalAssistantSystemPrompt(payload, externalUser, options) {
|
|
136
|
+
const body = {
|
|
137
|
+
...payload,
|
|
138
|
+
};
|
|
139
|
+
if (externalUser) {
|
|
140
|
+
body.external_user = normalizeExternalUserIdentity(externalUser);
|
|
141
|
+
}
|
|
142
|
+
return this.post('external_users/assistant/set_system_prompt', body, options);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Create an assistant completion scoped to an external user while billing that external user's credit balance.
|
|
146
|
+
* The owning Samsar account's configured assistant model is used internally.
|
|
147
|
+
*/
|
|
148
|
+
async createExternalAssistantCompletion(payload, externalUser, options) {
|
|
149
|
+
const body = {
|
|
150
|
+
...payload,
|
|
151
|
+
};
|
|
152
|
+
if (externalUser) {
|
|
153
|
+
body.external_user = normalizeExternalUserIdentity(externalUser);
|
|
154
|
+
}
|
|
155
|
+
return this.post('external_users/assistant/completion', body, options);
|
|
156
|
+
}
|
|
131
157
|
/**
|
|
132
158
|
* Translate an existing video session into a new language.
|
|
133
159
|
* Creates a new session_id and queues generation steps for lip sync + transcription + video render.
|