samsar-js 0.48.10 → 0.48.12
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 +35 -2
- package/dist/index.d.ts +113 -0
- package/dist/index.js +35 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -150,13 +150,29 @@ const embedding = await samsar.createEmbedding({
|
|
|
150
150
|
// Create embeddings from one URL or a URL list
|
|
151
151
|
const websiteEmbedding = await samsar.createEmbeddingFromUrl({
|
|
152
152
|
name: 'product-docs',
|
|
153
|
+
levels: 2,
|
|
153
154
|
urls: [
|
|
154
155
|
'https://example.com/docs/getting-started',
|
|
155
156
|
'https://example.com/docs/pricing',
|
|
156
157
|
],
|
|
157
158
|
});
|
|
158
159
|
|
|
159
|
-
//
|
|
160
|
+
// `levels` controls crawl depth for URL mode: 1 = only listed URLs, 2 = one link hop, 3 = two link hops.
|
|
161
|
+
// The API defaults to 2 levels and caps total crawled pages at 50 per request.
|
|
162
|
+
|
|
163
|
+
// Create embeddings from already cleaned plain text without crawling
|
|
164
|
+
const cleanTextEmbedding = await samsar.generateEmbeddingsFromPlainText({
|
|
165
|
+
name: 'product-docs-clean',
|
|
166
|
+
plain_text: [
|
|
167
|
+
{
|
|
168
|
+
url: 'https://example.com/docs/getting-started',
|
|
169
|
+
title: 'Getting Started',
|
|
170
|
+
content: 'Cleaned plain text content from the page.',
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// The generic createEmbedding wrapper also accepts `urls` plus `levels` on the same route if you prefer one entrypoint.
|
|
160
176
|
|
|
161
177
|
// Search against an embedding template
|
|
162
178
|
const search = await samsar.searchAgainstEmbedding({
|
|
@@ -321,6 +337,22 @@ const externalAssistant = await platform.createExternalAssistantCompletion(
|
|
|
321
337
|
);
|
|
322
338
|
console.log(externalAssistant.data.output_text);
|
|
323
339
|
|
|
340
|
+
// Build embeddings for that external user from already cleaned plain text
|
|
341
|
+
const externalEmbedding = await platform.generateExternalEmbeddingsFromPlainText(
|
|
342
|
+
{
|
|
343
|
+
name: 'creator-docs-clean',
|
|
344
|
+
plain_text: [
|
|
345
|
+
{
|
|
346
|
+
url: 'https://example.com/creator/faq',
|
|
347
|
+
title: 'Creator FAQ',
|
|
348
|
+
content: 'Cleaned plain text content for this external user.',
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
},
|
|
352
|
+
externalUser,
|
|
353
|
+
);
|
|
354
|
+
console.log(externalEmbedding.data.template_id);
|
|
355
|
+
|
|
324
356
|
// Fetch their external library
|
|
325
357
|
const library = await platform.listExternalUserRequests(externalUser, { limit: 12 });
|
|
326
358
|
console.log(library.data.requests.length);
|
|
@@ -364,7 +396,8 @@ Each method returns `{ data, status, headers, creditsCharged, creditsRemaining,
|
|
|
364
396
|
|
|
365
397
|
- 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.
|
|
366
398
|
- Embedding endpoints (`createEmbedding`, `updateEmbedding`, `searchAgainstEmbedding`, `similarToEmbedding`) are billed by input tokens at $1 per million tokens. `deleteEmbeddings` does not consume tokens.
|
|
367
|
-
- URL-based embedding creation (`createEmbedding` with `urls`, or `createEmbeddingFromUrl`)
|
|
399
|
+
- URL-based embedding creation (`createEmbedding` with `urls`, or `createEmbeddingFromUrl`) supports `levels` 1-3, defaults to 2, caps total crawled pages at 50 per request, bills actual Firecrawl usage with a `2.5x` crawl multiplier, and then bills the embedding phase with a separate flat `2.5x` multiplier.
|
|
400
|
+
- Plain-text embedding creation (`generateEmbeddingsFromPlainText`, `generateExternalEmbeddingsFromPlainText`) skips crawling and charges only the embedding-token cost with a flat `2.5x` multiplier.
|
|
368
401
|
- 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.
|
|
369
402
|
- Receipt template creation (`createReceiptTemplate`) and template JSON lookup (`getReceiptTemplateJson`) are free; receipt template query (`queryReceiptTemplate`) costs 50 credits per request.
|
|
370
403
|
|
package/dist/index.d.ts
CHANGED
|
@@ -407,6 +407,22 @@ export interface EmbeddingFieldOptions {
|
|
|
407
407
|
retrievable?: boolean;
|
|
408
408
|
}
|
|
409
409
|
export type EmbeddingUrlInput = string | string[];
|
|
410
|
+
export interface PlainTextEmbeddingEntry {
|
|
411
|
+
plain_text?: string;
|
|
412
|
+
plainText?: string;
|
|
413
|
+
content?: string;
|
|
414
|
+
text?: string;
|
|
415
|
+
cleaned_text?: string;
|
|
416
|
+
cleanedText?: string;
|
|
417
|
+
markdown?: string;
|
|
418
|
+
body?: string;
|
|
419
|
+
url?: string;
|
|
420
|
+
title?: string;
|
|
421
|
+
description?: string;
|
|
422
|
+
language?: string;
|
|
423
|
+
[key: string]: unknown;
|
|
424
|
+
}
|
|
425
|
+
export type PlainTextEmbeddingInput = string | PlainTextEmbeddingEntry | Array<string | PlainTextEmbeddingEntry>;
|
|
410
426
|
export type EmbeddingFieldOptionsInput = Record<string, EmbeddingFieldOptions> | Array<EmbeddingFieldOptions & {
|
|
411
427
|
key?: string;
|
|
412
428
|
field?: string;
|
|
@@ -424,6 +440,7 @@ export interface CreateEmbeddingRequest {
|
|
|
424
440
|
records?: Array<Record<string, unknown>>;
|
|
425
441
|
urls?: EmbeddingUrlInput;
|
|
426
442
|
url?: string;
|
|
443
|
+
levels?: number;
|
|
427
444
|
name?: string;
|
|
428
445
|
embedding_name?: string;
|
|
429
446
|
template_name?: string;
|
|
@@ -434,6 +451,33 @@ export interface CreateEmbeddingRequest {
|
|
|
434
451
|
export interface CreateEmbeddingFromUrlRequest {
|
|
435
452
|
urls?: EmbeddingUrlInput;
|
|
436
453
|
url?: string;
|
|
454
|
+
levels?: number;
|
|
455
|
+
name?: string;
|
|
456
|
+
embedding_name?: string;
|
|
457
|
+
template_name?: string;
|
|
458
|
+
field_options?: EmbeddingFieldOptionsInput;
|
|
459
|
+
fieldOptions?: EmbeddingFieldOptionsInput;
|
|
460
|
+
[key: string]: unknown;
|
|
461
|
+
}
|
|
462
|
+
export interface GenerateEmbeddingsFromPlainTextRequest {
|
|
463
|
+
plain_text?: PlainTextEmbeddingInput;
|
|
464
|
+
plainText?: PlainTextEmbeddingInput;
|
|
465
|
+
plain_texts?: PlainTextEmbeddingInput;
|
|
466
|
+
plainTexts?: PlainTextEmbeddingInput;
|
|
467
|
+
texts?: PlainTextEmbeddingInput;
|
|
468
|
+
documents?: PlainTextEmbeddingInput;
|
|
469
|
+
items?: PlainTextEmbeddingInput;
|
|
470
|
+
entries?: PlainTextEmbeddingInput;
|
|
471
|
+
content?: string;
|
|
472
|
+
text?: string;
|
|
473
|
+
cleaned_text?: string;
|
|
474
|
+
cleanedText?: string;
|
|
475
|
+
markdown?: string;
|
|
476
|
+
body?: string;
|
|
477
|
+
url?: string;
|
|
478
|
+
title?: string;
|
|
479
|
+
description?: string;
|
|
480
|
+
language?: string;
|
|
437
481
|
name?: string;
|
|
438
482
|
embedding_name?: string;
|
|
439
483
|
template_name?: string;
|
|
@@ -449,6 +493,8 @@ export interface CreateEmbeddingResponse {
|
|
|
449
493
|
input_url_count?: number;
|
|
450
494
|
processed_url_count?: number;
|
|
451
495
|
firecrawl_credits_used?: number;
|
|
496
|
+
crawl_levels?: number;
|
|
497
|
+
max_links?: number;
|
|
452
498
|
skipped_urls?: EmbeddingUrlIssue[];
|
|
453
499
|
crawl_errors?: EmbeddingUrlIssue[];
|
|
454
500
|
structured_fields?: EmbeddingStructuredField[];
|
|
@@ -969,6 +1015,52 @@ export interface ExternalCreditsGrantResponse {
|
|
|
969
1015
|
external_user?: ExternalUserSummary | null;
|
|
970
1016
|
[key: string]: unknown;
|
|
971
1017
|
}
|
|
1018
|
+
export interface ExternalUtilityChargeRequest {
|
|
1019
|
+
utility_type?: string;
|
|
1020
|
+
utilityType?: string;
|
|
1021
|
+
type?: string;
|
|
1022
|
+
provider?: string;
|
|
1023
|
+
model?: string;
|
|
1024
|
+
model_id?: string;
|
|
1025
|
+
modelId?: string;
|
|
1026
|
+
text?: string;
|
|
1027
|
+
content?: string;
|
|
1028
|
+
characters?: number;
|
|
1029
|
+
character_count?: number;
|
|
1030
|
+
characterCount?: number;
|
|
1031
|
+
duration_ms?: number;
|
|
1032
|
+
durationMs?: number;
|
|
1033
|
+
duration_seconds?: number;
|
|
1034
|
+
durationSeconds?: number;
|
|
1035
|
+
duration_minutes?: number;
|
|
1036
|
+
durationMinutes?: number;
|
|
1037
|
+
duration_hours?: number;
|
|
1038
|
+
durationHours?: number;
|
|
1039
|
+
firecrawl_credits_used?: number;
|
|
1040
|
+
firecrawlCreditsUsed?: number;
|
|
1041
|
+
pricing_multiplier?: number;
|
|
1042
|
+
pricingMultiplier?: number;
|
|
1043
|
+
multiplier?: number;
|
|
1044
|
+
metadata?: Record<string, unknown>;
|
|
1045
|
+
[key: string]: unknown;
|
|
1046
|
+
}
|
|
1047
|
+
export interface ExternalUtilityChargeResponse {
|
|
1048
|
+
utilityType?: string;
|
|
1049
|
+
provider?: string | null;
|
|
1050
|
+
model?: string | null;
|
|
1051
|
+
creditsCharged?: number;
|
|
1052
|
+
remainingCredits?: number | null;
|
|
1053
|
+
pricing?: {
|
|
1054
|
+
costUsd?: number;
|
|
1055
|
+
pricingMultiplier?: number;
|
|
1056
|
+
creditsPerDollar?: number;
|
|
1057
|
+
units?: Record<string, unknown>;
|
|
1058
|
+
[key: string]: unknown;
|
|
1059
|
+
} | null;
|
|
1060
|
+
externalUser?: ExternalUserSummary | null;
|
|
1061
|
+
external_user?: ExternalUserSummary | null;
|
|
1062
|
+
[key: string]: unknown;
|
|
1063
|
+
}
|
|
972
1064
|
export interface ExternalCreditsRechargeResponse extends CreditsRechargeResponse {
|
|
973
1065
|
external_payment_id?: string;
|
|
974
1066
|
external_user?: ExternalUserSummary | null;
|
|
@@ -1083,6 +1175,10 @@ export interface ExternalAssistantSetSystemPromptResponse extends AssistantSetSy
|
|
|
1083
1175
|
external_user?: ExternalUserSummary | null;
|
|
1084
1176
|
externalUser?: ExternalUserSummary | null;
|
|
1085
1177
|
}
|
|
1178
|
+
export interface ExternalCreateEmbeddingResponse extends CreateEmbeddingResponse {
|
|
1179
|
+
external_user?: ExternalUserSummary | null;
|
|
1180
|
+
externalUser?: ExternalUserSummary | null;
|
|
1181
|
+
}
|
|
1086
1182
|
export interface VerifyClientSessionInput {
|
|
1087
1183
|
loginToken?: string;
|
|
1088
1184
|
authToken?: string;
|
|
@@ -1255,6 +1351,11 @@ export declare class SamsarClient {
|
|
|
1255
1351
|
sessionName?: string;
|
|
1256
1352
|
metadata?: Record<string, unknown>;
|
|
1257
1353
|
}, options?: SamsarRequestOptions): Promise<SamsarResult<ExternalAssistantSessionResponse>>;
|
|
1354
|
+
/**
|
|
1355
|
+
* Charge an external user's credits for utility usage such as ElevenLabs TTS/STT or Firecrawl crawl costs.
|
|
1356
|
+
* This is useful when a proxy or integration incurs third-party usage outside the standard Samsar route billing flow.
|
|
1357
|
+
*/
|
|
1358
|
+
chargeExternalUserUtilityUsage(payload: ExternalUtilityChargeRequest, externalUser?: ExternalUserIdentity | null, options?: SamsarRequestOptions): Promise<SamsarResult<ExternalUtilityChargeResponse>>;
|
|
1258
1359
|
/**
|
|
1259
1360
|
* Create a short-lived external-user login token plus a ready-to-open client login URL.
|
|
1260
1361
|
*/
|
|
@@ -1271,6 +1372,11 @@ export declare class SamsarClient {
|
|
|
1271
1372
|
* The owning Samsar account's configured assistant model is used internally.
|
|
1272
1373
|
*/
|
|
1273
1374
|
createExternalAssistantCompletion(payload: AssistantCompletionRequest, externalUser?: ExternalUserIdentity | null, options?: SamsarRequestOptions): Promise<SamsarResult<AssistantCompletionResponse>>;
|
|
1375
|
+
/**
|
|
1376
|
+
* Create a new embedding template for an external user from already cleaned plain text.
|
|
1377
|
+
* This skips crawling and bills the external user's credits only.
|
|
1378
|
+
*/
|
|
1379
|
+
generateExternalEmbeddingsFromPlainText(payload: GenerateEmbeddingsFromPlainTextRequest, externalUser?: ExternalUserIdentity | null, options?: SamsarRequestOptions): Promise<SamsarResult<ExternalCreateEmbeddingResponse>>;
|
|
1274
1380
|
/**
|
|
1275
1381
|
* Translate an existing video session into a new language.
|
|
1276
1382
|
* Creates a new session_id and queues generation steps for lip sync + transcription + video render.
|
|
@@ -1344,12 +1450,19 @@ export declare class SamsarClient {
|
|
|
1344
1450
|
createAssistantCompletion(payload: AssistantCompletionRequest, options?: SamsarRequestOptions): Promise<SamsarResult<AssistantCompletionResponse>>;
|
|
1345
1451
|
/**
|
|
1346
1452
|
* Create a new embedding template from either a JSON array (`records`) or a URL input (`urls`).
|
|
1453
|
+
* URL mode also accepts `levels` (1-3) to control crawl depth.
|
|
1347
1454
|
*/
|
|
1348
1455
|
createEmbedding(payload: CreateEmbeddingRequest, options?: SamsarRequestOptions): Promise<SamsarResult<CreateEmbeddingResponse>>;
|
|
1349
1456
|
/**
|
|
1350
1457
|
* Create a new embedding template from one URL or a list of URLs.
|
|
1458
|
+
* Pass `levels` (1-3) to control crawl depth; the API defaults to 2.
|
|
1351
1459
|
*/
|
|
1352
1460
|
createEmbeddingFromUrl(payload: CreateEmbeddingFromUrlRequest, options?: SamsarRequestOptions): Promise<SamsarResult<CreateEmbeddingResponse>>;
|
|
1461
|
+
/**
|
|
1462
|
+
* Create a new embedding template from already cleaned plain text.
|
|
1463
|
+
* This skips crawling and uses the same compatible template format as the JSON and URL routes.
|
|
1464
|
+
*/
|
|
1465
|
+
generateEmbeddingsFromPlainText(payload: GenerateEmbeddingsFromPlainTextRequest, options?: SamsarRequestOptions): Promise<SamsarResult<CreateEmbeddingResponse>>;
|
|
1353
1466
|
/**
|
|
1354
1467
|
* Update an existing embedding template with additional records.
|
|
1355
1468
|
*/
|
package/dist/index.js
CHANGED
|
@@ -128,6 +128,19 @@ export class SamsarClient {
|
|
|
128
128
|
}
|
|
129
129
|
return this.post('external_users/utils/assistant_session', body, options);
|
|
130
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Charge an external user's credits for utility usage such as ElevenLabs TTS/STT or Firecrawl crawl costs.
|
|
133
|
+
* This is useful when a proxy or integration incurs third-party usage outside the standard Samsar route billing flow.
|
|
134
|
+
*/
|
|
135
|
+
async chargeExternalUserUtilityUsage(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/utils/usage_charge', body, options);
|
|
143
|
+
}
|
|
131
144
|
/**
|
|
132
145
|
* Create a short-lived external-user login token plus a ready-to-open client login URL.
|
|
133
146
|
*/
|
|
@@ -167,6 +180,19 @@ export class SamsarClient {
|
|
|
167
180
|
}
|
|
168
181
|
return this.post('external_users/assistant/completion', body, options);
|
|
169
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Create a new embedding template for an external user from already cleaned plain text.
|
|
185
|
+
* This skips crawling and bills the external user's credits only.
|
|
186
|
+
*/
|
|
187
|
+
async generateExternalEmbeddingsFromPlainText(payload, externalUser, options) {
|
|
188
|
+
const body = {
|
|
189
|
+
...payload,
|
|
190
|
+
};
|
|
191
|
+
if (externalUser) {
|
|
192
|
+
body.external_user = normalizeExternalUserIdentity(externalUser);
|
|
193
|
+
}
|
|
194
|
+
return this.post('external_users/generate_embeddings_from_plain_text', body, options);
|
|
195
|
+
}
|
|
170
196
|
/**
|
|
171
197
|
* Translate an existing video session into a new language.
|
|
172
198
|
* Creates a new session_id and queues generation steps for lip sync + transcription + video render.
|
|
@@ -605,16 +631,25 @@ export class SamsarClient {
|
|
|
605
631
|
}
|
|
606
632
|
/**
|
|
607
633
|
* Create a new embedding template from either a JSON array (`records`) or a URL input (`urls`).
|
|
634
|
+
* URL mode also accepts `levels` (1-3) to control crawl depth.
|
|
608
635
|
*/
|
|
609
636
|
async createEmbedding(payload, options) {
|
|
610
637
|
return this.post('chat/create_embedding', payload, options);
|
|
611
638
|
}
|
|
612
639
|
/**
|
|
613
640
|
* Create a new embedding template from one URL or a list of URLs.
|
|
641
|
+
* Pass `levels` (1-3) to control crawl depth; the API defaults to 2.
|
|
614
642
|
*/
|
|
615
643
|
async createEmbeddingFromUrl(payload, options) {
|
|
616
644
|
return this.post('chat/create_embedding_from_url', payload, options);
|
|
617
645
|
}
|
|
646
|
+
/**
|
|
647
|
+
* Create a new embedding template from already cleaned plain text.
|
|
648
|
+
* This skips crawling and uses the same compatible template format as the JSON and URL routes.
|
|
649
|
+
*/
|
|
650
|
+
async generateEmbeddingsFromPlainText(payload, options) {
|
|
651
|
+
return this.post('chat/generate_embeddings_from_plain_text', payload, options);
|
|
652
|
+
}
|
|
618
653
|
/**
|
|
619
654
|
* Update an existing embedding template with additional records.
|
|
620
655
|
*/
|