samsar-js 0.48.4 → 0.48.5
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 +23 -2
- package/dist/index.d.ts +87 -0
- package/dist/index.js +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# samsar-js
|
|
2
2
|
|
|
3
|
-
TypeScript/ESM client for the Samsar Processor public API (`https://api.samsar.one/v1`). It mirrors
|
|
3
|
+
TypeScript/ESM client for the Samsar Processor public API (`https://api.samsar.one/v1`). It mirrors OpenAI-style ergonomics for creating videos, enhancing copy, running assistant completions, and managing image operations.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -95,6 +95,26 @@ console.log(cancelled.data.status, cancelled.data.cancelled);
|
|
|
95
95
|
// Enhance chat message
|
|
96
96
|
const enhanced = await samsar.enhanceMessage({ message: 'Please improve this caption.' });
|
|
97
97
|
|
|
98
|
+
// Set an account-level assistant system prompt
|
|
99
|
+
await samsar.setAssistantSystemPrompt({
|
|
100
|
+
system_prompt: 'You are the brand assistant for Acme. Keep answers concise and commercially practical.',
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Create an assistant completion for an existing session
|
|
104
|
+
const assistant = await samsar.createAssistantCompletion({
|
|
105
|
+
session_id: videoFromImages.data.session_id ?? videoFromImages.data.request_id!,
|
|
106
|
+
input: [
|
|
107
|
+
{
|
|
108
|
+
role: 'user',
|
|
109
|
+
content: [
|
|
110
|
+
{ type: 'input_text', text: 'Write a launch caption for this session.' },
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
max_output_tokens: 300,
|
|
115
|
+
});
|
|
116
|
+
console.log(assistant.data.output_text);
|
|
117
|
+
|
|
98
118
|
// Create embeddings from a JSON array
|
|
99
119
|
const embedding = await samsar.createEmbedding({
|
|
100
120
|
name: 'listings',
|
|
@@ -304,9 +324,10 @@ Each method returns `{ data, status, headers, creditsCharged, creditsRemaining,
|
|
|
304
324
|
|
|
305
325
|
## Billing notes
|
|
306
326
|
|
|
327
|
+
- Assistant completions are billed from actual request usage. Samsar measures the processed input and generated output, converts usage to credits using the standard `100 credits = $1` rule, and applies a `2.5x` assistant multiplier so text-only and multimodal sessions are priced consistently.
|
|
307
328
|
- Embedding endpoints (`createEmbedding`, `updateEmbedding`, `searchAgainstEmbedding`, `similarToEmbedding`) are billed by input tokens at $1 per million tokens. `deleteEmbeddings` does not consume tokens.
|
|
308
329
|
- URL-based embedding creation (`createEmbedding` with `urls`, or `createEmbeddingFromUrl`) adds Firecrawl crawl cost to the embedding token cost, then applies Samsar's 100 credits per USD mapping with a `2.5x` multiplier.
|
|
309
|
-
- Token
|
|
330
|
+
- Token-based routes scale with the amount of content processed. Larger prompts, longer responses, and richer inputs use more credits than short text-only requests.
|
|
310
331
|
- Receipt template creation (`createReceiptTemplate`) and template JSON lookup (`getReceiptTemplateJson`) are free; receipt template query (`queryReceiptTemplate`) costs 50 credits per request.
|
|
311
332
|
|
|
312
333
|
## Configuration
|
package/dist/index.d.ts
CHANGED
|
@@ -297,6 +297,83 @@ export interface EnhanceMessageResponse {
|
|
|
297
297
|
content: string;
|
|
298
298
|
[key: string]: unknown;
|
|
299
299
|
}
|
|
300
|
+
export type AssistantInputContentItem = {
|
|
301
|
+
type: 'input_text' | 'text';
|
|
302
|
+
text: string;
|
|
303
|
+
[key: string]: unknown;
|
|
304
|
+
} | {
|
|
305
|
+
type: 'input_image' | 'image_url' | 'image';
|
|
306
|
+
image_url?: string;
|
|
307
|
+
url?: string;
|
|
308
|
+
[key: string]: unknown;
|
|
309
|
+
} | Record<string, unknown>;
|
|
310
|
+
export interface AssistantInputMessage {
|
|
311
|
+
role: 'user' | 'assistant' | 'developer' | 'system';
|
|
312
|
+
content: string | AssistantInputContentItem[];
|
|
313
|
+
[key: string]: unknown;
|
|
314
|
+
}
|
|
315
|
+
export interface AssistantReasoningConfig {
|
|
316
|
+
effort?: 'low' | 'medium' | 'high' | string;
|
|
317
|
+
[key: string]: unknown;
|
|
318
|
+
}
|
|
319
|
+
export interface AssistantSetSystemPromptRequest {
|
|
320
|
+
system_prompt?: string | null;
|
|
321
|
+
systemPrompt?: string | null;
|
|
322
|
+
prompt?: string | null;
|
|
323
|
+
value?: string | null;
|
|
324
|
+
}
|
|
325
|
+
export interface AssistantSetSystemPromptResponse {
|
|
326
|
+
system_prompt: string | null;
|
|
327
|
+
model?: string;
|
|
328
|
+
selected_assistant_model?: string;
|
|
329
|
+
[key: string]: unknown;
|
|
330
|
+
}
|
|
331
|
+
export interface AssistantCompletionRequest {
|
|
332
|
+
session_id?: string;
|
|
333
|
+
sessionId?: string;
|
|
334
|
+
id?: string;
|
|
335
|
+
input?: string | AssistantInputMessage | AssistantInputMessage[] | AssistantInputContentItem[];
|
|
336
|
+
message?: string | AssistantInputMessage | AssistantInputMessage[] | AssistantInputContentItem[];
|
|
337
|
+
messages?: AssistantInputMessage[];
|
|
338
|
+
max_output_tokens?: number;
|
|
339
|
+
maxOutputTokens?: number;
|
|
340
|
+
max_tokens?: number;
|
|
341
|
+
temperature?: number;
|
|
342
|
+
top_p?: number;
|
|
343
|
+
metadata?: Record<string, unknown>;
|
|
344
|
+
user?: string;
|
|
345
|
+
text?: Record<string, unknown>;
|
|
346
|
+
tools?: unknown[];
|
|
347
|
+
tool_choice?: unknown;
|
|
348
|
+
parallel_tool_calls?: boolean;
|
|
349
|
+
reasoning?: AssistantReasoningConfig;
|
|
350
|
+
reasoning_effort?: 'low' | 'medium' | 'high' | string;
|
|
351
|
+
[key: string]: unknown;
|
|
352
|
+
}
|
|
353
|
+
export interface AssistantResponseContentItem {
|
|
354
|
+
type?: string;
|
|
355
|
+
text?: string;
|
|
356
|
+
annotations?: unknown[];
|
|
357
|
+
[key: string]: unknown;
|
|
358
|
+
}
|
|
359
|
+
export interface AssistantResponseOutputItem {
|
|
360
|
+
id?: string;
|
|
361
|
+
type?: string;
|
|
362
|
+
role?: string;
|
|
363
|
+
content?: AssistantResponseContentItem[];
|
|
364
|
+
[key: string]: unknown;
|
|
365
|
+
}
|
|
366
|
+
export interface AssistantCompletionResponse {
|
|
367
|
+
id?: string;
|
|
368
|
+
object?: string;
|
|
369
|
+
created_at?: number;
|
|
370
|
+
status?: string;
|
|
371
|
+
model?: string;
|
|
372
|
+
output_text?: string;
|
|
373
|
+
output?: AssistantResponseOutputItem[];
|
|
374
|
+
usage?: Record<string, unknown>;
|
|
375
|
+
[key: string]: unknown;
|
|
376
|
+
}
|
|
300
377
|
export interface EmbeddingStructuredField {
|
|
301
378
|
key: string;
|
|
302
379
|
type: string;
|
|
@@ -1194,6 +1271,16 @@ export declare class SamsarClient {
|
|
|
1194
1271
|
* Optionally pass `language` (code or name) to enforce the output language.
|
|
1195
1272
|
*/
|
|
1196
1273
|
enhanceMessage(payload: EnhanceMessageRequest, options?: SamsarRequestOptions): Promise<SamsarResult<EnhanceMessageResponse>>;
|
|
1274
|
+
/**
|
|
1275
|
+
* Store or clear the account-level system prompt used by assistant completions.
|
|
1276
|
+
* Pass `null` (for `system_prompt`) or an empty string to clear the custom prompt and revert to Samsar's default assistant prompt.
|
|
1277
|
+
*/
|
|
1278
|
+
setAssistantSystemPrompt(payload: AssistantSetSystemPromptRequest, options?: SamsarRequestOptions): Promise<SamsarResult<AssistantSetSystemPromptResponse>>;
|
|
1279
|
+
/**
|
|
1280
|
+
* Create an assistant completion for an existing session.
|
|
1281
|
+
* Returns an OpenAI Responses-style payload and includes credit headers when applicable.
|
|
1282
|
+
*/
|
|
1283
|
+
createAssistantCompletion(payload: AssistantCompletionRequest, options?: SamsarRequestOptions): Promise<SamsarResult<AssistantCompletionResponse>>;
|
|
1197
1284
|
/**
|
|
1198
1285
|
* Create a new embedding template from either a JSON array (`records`) or a URL input (`urls`).
|
|
1199
1286
|
*/
|
package/dist/index.js
CHANGED
|
@@ -550,6 +550,20 @@ export class SamsarClient {
|
|
|
550
550
|
async enhanceMessage(payload, options) {
|
|
551
551
|
return this.post('chat/enhance', payload, options);
|
|
552
552
|
}
|
|
553
|
+
/**
|
|
554
|
+
* Store or clear the account-level system prompt used by assistant completions.
|
|
555
|
+
* Pass `null` (for `system_prompt`) or an empty string to clear the custom prompt and revert to Samsar's default assistant prompt.
|
|
556
|
+
*/
|
|
557
|
+
async setAssistantSystemPrompt(payload, options) {
|
|
558
|
+
return this.post('assistant/set_system_prompt', payload, options);
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Create an assistant completion for an existing session.
|
|
562
|
+
* Returns an OpenAI Responses-style payload and includes credit headers when applicable.
|
|
563
|
+
*/
|
|
564
|
+
async createAssistantCompletion(payload, options) {
|
|
565
|
+
return this.post('assistant/completion', payload, options);
|
|
566
|
+
}
|
|
553
567
|
/**
|
|
554
568
|
* Create a new embedding template from either a JSON array (`records`) or a URL input (`urls`).
|
|
555
569
|
*/
|