@constal/sdk 5.3.0 → 6.0.0
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/NOTICE +4 -0
- package/package.json +7 -1
- package/publish/api.json +51 -2
- package/publish/chat-format.d.ts +172 -0
- package/publish/chat-format.js +5989 -0
- package/publish/index.d.ts +551 -165
- package/publish/index.js +1200 -761
package/NOTICE
CHANGED
|
@@ -2,3 +2,7 @@ Constal SDK
|
|
|
2
2
|
Copyright 2026 Coresource AI, Inc.
|
|
3
3
|
|
|
4
4
|
This product includes software developed by Coresource AI, Inc.
|
|
5
|
+
|
|
6
|
+
The @constal/sdk/chat-format entry point bundles:
|
|
7
|
+
- @huggingface/jinja, Copyright (c) Hugging Face, under the MIT License.
|
|
8
|
+
- @huggingface/tokenizers, Copyright Hugging Face, under the Apache License 2.0.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constal/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Public TypeScript SDK for authoring Constal agents, integrations, policies, channels, and credential providers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"constal",
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./publish/index.d.ts",
|
|
21
21
|
"import": "./publish/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./chat-format": {
|
|
24
|
+
"types": "./publish/chat-format.d.ts",
|
|
25
|
+
"import": "./publish/chat-format.js"
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
28
|
"files": [
|
|
@@ -36,6 +40,8 @@
|
|
|
36
40
|
"prepack": "npm run typecheck && npm test && npm run build"
|
|
37
41
|
},
|
|
38
42
|
"devDependencies": {
|
|
43
|
+
"@huggingface/jinja": "0.5.10",
|
|
44
|
+
"@huggingface/tokenizers": "^0.1.3",
|
|
39
45
|
"esbuild": "^0.28.2",
|
|
40
46
|
"rollup": "^4.62.4",
|
|
41
47
|
"rollup-plugin-dts": "^6.2.3"
|
package/publish/api.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"package": "@constal/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"exports": [
|
|
5
5
|
"AGENT_UI_DEFAULTS",
|
|
6
6
|
"Action",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"BoundOperation",
|
|
41
41
|
"BoundResourceCapabilities",
|
|
42
42
|
"BranchRef",
|
|
43
|
+
"CHAT_FORMAT_CAPABILITY",
|
|
43
44
|
"CONSTAL_API_CAPABILITY",
|
|
44
45
|
"CONSTAL_API_GET_KINDS",
|
|
45
46
|
"CONSTAL_API_MODEL_TOOL_DESCRIPTIONS",
|
|
@@ -74,6 +75,16 @@
|
|
|
74
75
|
"ChannelSourceEvidence",
|
|
75
76
|
"ChannelSubscriptionRequest",
|
|
76
77
|
"ChannelTarget",
|
|
78
|
+
"ChatFormatDefinition",
|
|
79
|
+
"ChatFormatMetadata",
|
|
80
|
+
"ChatFormatPin",
|
|
81
|
+
"ChatMessage",
|
|
82
|
+
"ChatParseRequest",
|
|
83
|
+
"ChatParsed",
|
|
84
|
+
"ChatRenderRequest",
|
|
85
|
+
"ChatRendering",
|
|
86
|
+
"ChatSpan",
|
|
87
|
+
"ChatTool",
|
|
77
88
|
"CheckpointDeploymentRequest",
|
|
78
89
|
"CheckpointImportMetadata",
|
|
79
90
|
"CheckpointImportRequest",
|
|
@@ -138,7 +149,9 @@
|
|
|
138
149
|
"CredentialVerifyResult",
|
|
139
150
|
"Ctx",
|
|
140
151
|
"CustomerTenantCRN",
|
|
152
|
+
"DATA_SHARE_FEE_BPS",
|
|
141
153
|
"DataManifest",
|
|
154
|
+
"DataSharingScope",
|
|
142
155
|
"DatasetCRN",
|
|
143
156
|
"DatasetDraft",
|
|
144
157
|
"DatasetRef",
|
|
@@ -272,6 +285,7 @@
|
|
|
272
285
|
"ModelTool",
|
|
273
286
|
"NondeterministicReplay",
|
|
274
287
|
"NormalizedModelGatewayConfig",
|
|
288
|
+
"NotAppendOnly",
|
|
275
289
|
"NoulAnswer",
|
|
276
290
|
"NoulQuestion",
|
|
277
291
|
"Out",
|
|
@@ -394,6 +408,22 @@
|
|
|
394
408
|
"SetupSubmission",
|
|
395
409
|
"SetupTerminalPanel",
|
|
396
410
|
"SetupWorkflowStatus",
|
|
411
|
+
"Share",
|
|
412
|
+
"ShareAction",
|
|
413
|
+
"ShareContribution",
|
|
414
|
+
"ShareContributionImport",
|
|
415
|
+
"ShareContributionRequest",
|
|
416
|
+
"ShareContributionReview",
|
|
417
|
+
"ShareContributionReviewRequest",
|
|
418
|
+
"ShareContributionStatus",
|
|
419
|
+
"ShareEvaluation",
|
|
420
|
+
"ShareEvaluationPin",
|
|
421
|
+
"ShareEvaluationRequest",
|
|
422
|
+
"ShareEvaluationVerdict",
|
|
423
|
+
"ShareEvaluationView",
|
|
424
|
+
"SharePrice",
|
|
425
|
+
"ShareRequest",
|
|
426
|
+
"ShareReviewDecision",
|
|
397
427
|
"Skill",
|
|
398
428
|
"SkillDescription",
|
|
399
429
|
"SkillLibrary",
|
|
@@ -412,6 +442,7 @@
|
|
|
412
442
|
"SuiteFact",
|
|
413
443
|
"SwallowedYield",
|
|
414
444
|
"TRAINING_PROVIDER_CAPABILITY",
|
|
445
|
+
"TRAINING_RECIPE_DEFAULTS",
|
|
415
446
|
"TableAggregate",
|
|
416
447
|
"TableDescribeArgs",
|
|
417
448
|
"TableFilter",
|
|
@@ -428,17 +459,20 @@
|
|
|
428
459
|
"Tool",
|
|
429
460
|
"ToolCallRecord",
|
|
430
461
|
"ToolUnavailable",
|
|
462
|
+
"TrainingCorrection",
|
|
431
463
|
"TrainingJobFact",
|
|
432
464
|
"TrainingJobReference",
|
|
433
465
|
"TrainingJobState",
|
|
434
466
|
"TrainingJobStatus",
|
|
435
467
|
"TrainingMethod",
|
|
436
468
|
"TrainingModelOffer",
|
|
469
|
+
"TrainingPreparation",
|
|
437
470
|
"TrainingProviderDefinition",
|
|
438
471
|
"TrainingProviderMetadata",
|
|
439
472
|
"TrainingProviderPin",
|
|
440
473
|
"TrainingRecipe",
|
|
441
474
|
"TrainingResumePoint",
|
|
475
|
+
"TrainingStep",
|
|
442
476
|
"TrainingUsageUnits",
|
|
443
477
|
"TurnDraft",
|
|
444
478
|
"TurnGate",
|
|
@@ -493,6 +527,14 @@
|
|
|
493
527
|
"channelSourceEvidence",
|
|
494
528
|
"channelSubscriptionRequest",
|
|
495
529
|
"channelTarget",
|
|
530
|
+
"chatFormat",
|
|
531
|
+
"chatFormatMetadata",
|
|
532
|
+
"chatFormatPin",
|
|
533
|
+
"chatParseInput",
|
|
534
|
+
"chatParsed",
|
|
535
|
+
"chatRenderInput",
|
|
536
|
+
"chatRenderRequest",
|
|
537
|
+
"chatRendering",
|
|
496
538
|
"checkpointArtifactRef",
|
|
497
539
|
"checkpointDeploymentRequest",
|
|
498
540
|
"checkpointImportMetadata",
|
|
@@ -515,6 +557,7 @@
|
|
|
515
557
|
"customerTenantName",
|
|
516
558
|
"cutBatches",
|
|
517
559
|
"cutPartitions",
|
|
560
|
+
"dataShareEarningMicroUsd",
|
|
518
561
|
"datasetName",
|
|
519
562
|
"evaluateCodeScorer",
|
|
520
563
|
"evaluatePolicyDefinition",
|
|
@@ -562,7 +605,6 @@
|
|
|
562
605
|
"policy",
|
|
563
606
|
"policyName",
|
|
564
607
|
"race",
|
|
565
|
-
"renderTrainingCompletion",
|
|
566
608
|
"resolveBindingOwner",
|
|
567
609
|
"resolveContainerImageSource",
|
|
568
610
|
"resolveGatewayEgress",
|
|
@@ -576,6 +618,7 @@
|
|
|
576
618
|
"resourcePattern",
|
|
577
619
|
"resourceSelector",
|
|
578
620
|
"resourceTools",
|
|
621
|
+
"runLabels",
|
|
579
622
|
"sandboxControls",
|
|
580
623
|
"sandboxEgressDecision",
|
|
581
624
|
"sandboxEgressHostMatches",
|
|
@@ -594,12 +637,18 @@
|
|
|
594
637
|
"setupScreenView",
|
|
595
638
|
"setupSubmission",
|
|
596
639
|
"sha256Hex",
|
|
640
|
+
"shareContributionRequest",
|
|
641
|
+
"shareContributionReview",
|
|
642
|
+
"shareEvaluation",
|
|
643
|
+
"sharePrices",
|
|
644
|
+
"shareRequest",
|
|
597
645
|
"skills",
|
|
598
646
|
"stageOutput",
|
|
599
647
|
"startTrainingRequest",
|
|
600
648
|
"subtask",
|
|
601
649
|
"tableDescribe",
|
|
602
650
|
"tableQuery",
|
|
651
|
+
"trainingCorrection",
|
|
603
652
|
"trainingProvider",
|
|
604
653
|
"trainingProviderMetadata",
|
|
605
654
|
"trainingRecipe",
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
type Ref = string;
|
|
2
|
+
|
|
3
|
+
interface ModelTool {
|
|
4
|
+
name: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
description: string;
|
|
7
|
+
schema: object;
|
|
8
|
+
}
|
|
9
|
+
/** One Tool call an earlier assistant message made. `id` is the call's id in its turn's record (`ToolCallRecord.id`), which
|
|
10
|
+
* the tool message answering it names; `args` is the JSON value the model gave (`ToolCallRecord.args`). An OpenAI-protocol
|
|
11
|
+
* request sends it as the arguments text; an Anthropic `tool_use` input must be an object, so a value that is not one is
|
|
12
|
+
* sent as `{ value }`, as the Constal Gateway does for such a call. */
|
|
13
|
+
interface ModelHistoryToolCall {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
args: unknown;
|
|
17
|
+
}
|
|
18
|
+
/** One earlier message, oldest first. User and assistant text is as it always was; an assistant message may also carry the
|
|
19
|
+
* Tool calls it made, and a tool message returns one call's result to the model. The tool messages right after an
|
|
20
|
+
* assistant message answer each of its calls once, before any other message. */
|
|
21
|
+
type ModelHistoryMessage = {
|
|
22
|
+
role: "user";
|
|
23
|
+
content: string;
|
|
24
|
+
} | {
|
|
25
|
+
role: "assistant";
|
|
26
|
+
content: string;
|
|
27
|
+
toolCalls?: ModelHistoryToolCall[];
|
|
28
|
+
} | {
|
|
29
|
+
role: "tool";
|
|
30
|
+
toolCallId: string;
|
|
31
|
+
content: string;
|
|
32
|
+
isError?: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** A Tool offered to the model, as a chat template shows it. */
|
|
36
|
+
type ChatTool = Pick<ModelTool, "name" | "description" | "schema">;
|
|
37
|
+
/** One message of a conversation. An assistant message may carry the reasoning its turn produced. */
|
|
38
|
+
type ChatMessage = ModelHistoryMessage | {
|
|
39
|
+
role: "assistant";
|
|
40
|
+
content: string;
|
|
41
|
+
toolCalls?: ModelHistoryToolCall[];
|
|
42
|
+
reasoning?: string;
|
|
43
|
+
};
|
|
44
|
+
/** What a chat format renders: the same input for training and for serving. */
|
|
45
|
+
interface ChatRenderRequest {
|
|
46
|
+
system: string | null;
|
|
47
|
+
messages: ChatMessage[];
|
|
48
|
+
tools: ChatTool[];
|
|
49
|
+
toolChoice: "auto" | "required" | null;
|
|
50
|
+
effort: string | null;
|
|
51
|
+
/** Indexes of the assistant messages whose turns are trained, ascending; empty renders the generation prompt. */
|
|
52
|
+
train: number[];
|
|
53
|
+
}
|
|
54
|
+
/** The tokens of one trained assistant message: `start` inclusive, `end` exclusive, its end of turn included. */
|
|
55
|
+
interface ChatSpan {
|
|
56
|
+
message: number;
|
|
57
|
+
start: number;
|
|
58
|
+
end: number;
|
|
59
|
+
}
|
|
60
|
+
interface ChatRendering {
|
|
61
|
+
tokens: number[];
|
|
62
|
+
spans: ChatSpan[];
|
|
63
|
+
/** Tokens that end an assistant turn when sampling. */
|
|
64
|
+
stop: number[];
|
|
65
|
+
}
|
|
66
|
+
/** A conversation whose rendering of a trained turn changes once later messages follow it. */
|
|
67
|
+
declare class NotAppendOnly extends Error {
|
|
68
|
+
constructor(message?: string);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface ChatTemplateInput {
|
|
72
|
+
system: string | null;
|
|
73
|
+
messages: readonly ChatMessage[];
|
|
74
|
+
tools: readonly ChatTool[];
|
|
75
|
+
/** Appends the generation prompt. */
|
|
76
|
+
generation: boolean;
|
|
77
|
+
/** Further template variables: the tokenizer's special tokens, then the format's own, such as a thinking switch. */
|
|
78
|
+
variables?: Record<string, unknown>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Renders a Hugging Face chat template exactly as transformers' apply_chat_template does: trimmed blocks, json.dumps as
|
|
82
|
+
* tojson, the system prompt as the first message, Tools as OpenAI function schemas (none when empty), and the
|
|
83
|
+
* special tokens and other variables beside `messages`, `tools`, `documents` and `add_generation_prompt`.
|
|
84
|
+
*/
|
|
85
|
+
declare function renderChatTemplate(template: string, input: ChatTemplateInput): string;
|
|
86
|
+
/** How a format renders and tokenizes a request's messages, and the tokens that end its assistant turns. */
|
|
87
|
+
interface ChatSpanFormat {
|
|
88
|
+
/** The text of the request's first `count` messages; `generation` appends the generation prompt. */
|
|
89
|
+
render(count: number, generation: boolean): string;
|
|
90
|
+
encode(text: string): number[];
|
|
91
|
+
stop: readonly number[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The tokens of a request and the span of each trained assistant message. A trained message k is what its full render
|
|
95
|
+
* (messages 0..k) adds to its prompt render (messages 0..k-1 with the generation prompt), through its last stop token.
|
|
96
|
+
* Each full render must start with its prompt render, the whole render with each full render, and the pieces between
|
|
97
|
+
* those boundaries must tokenize to exactly the whole render's tokens; otherwise NotAppendOnly. With nothing trained it
|
|
98
|
+
* is the generation prompt.
|
|
99
|
+
*/
|
|
100
|
+
declare function chatSpans(request: Pick<ChatRenderRequest, "messages" | "train">, format: ChatSpanFormat): Pick<ChatRendering, "tokens" | "spans">;
|
|
101
|
+
/** A tokenizer with the chat template and special tokens of its tokenizer_config.json. */
|
|
102
|
+
interface ChatTokenizer {
|
|
103
|
+
/** The tokenizer's own chat template, null when it has none. */
|
|
104
|
+
template: string | null;
|
|
105
|
+
/** The special tokens a chat template sees beside its messages, as transformers passes them. */
|
|
106
|
+
variables: Record<string, unknown>;
|
|
107
|
+
encode(text: string): number[];
|
|
108
|
+
decode(tokens: readonly number[]): string;
|
|
109
|
+
/** The id of one token of the vocabulary. */
|
|
110
|
+
id(token: string): number;
|
|
111
|
+
}
|
|
112
|
+
/** A tokenizer from the parsed tokenizer.json and tokenizer_config.json of a Hugging Face repository. */
|
|
113
|
+
declare function chatTokenizer(definition: object, config: Record<string, unknown>): ChatTokenizer;
|
|
114
|
+
/** What a chat format loads its assets with: the content-addressed artifacts its Resource config names. */
|
|
115
|
+
interface ChatAssetLoader {
|
|
116
|
+
load(ref: Ref, maximumBytes: number): Promise<ArrayBuffer>;
|
|
117
|
+
}
|
|
118
|
+
/** Loads a tokenizer.json and tokenizer_config.json by their content addresses, once for as long as the format stays loaded. */
|
|
119
|
+
declare function loadChatTokenizer(context: ChatAssetLoader, assets: {
|
|
120
|
+
tokenizer: Ref;
|
|
121
|
+
config: Ref;
|
|
122
|
+
}): Promise<ChatTokenizer>;
|
|
123
|
+
/** One fixture: a request, the template variables its format adds, and what transformers rendered for it. */
|
|
124
|
+
interface ChatFormatGoldenCase {
|
|
125
|
+
name: string;
|
|
126
|
+
request: ChatRenderRequest;
|
|
127
|
+
/** Template variables beyond the special tokens that the format passes for this request. */
|
|
128
|
+
kwargs: Record<string, unknown>;
|
|
129
|
+
/** The whole template text; null when the reference refused the request. */
|
|
130
|
+
text: string | null;
|
|
131
|
+
rendering: ChatRendering | null;
|
|
132
|
+
/** The error the reference refused the request with, such as NotAppendOnly. */
|
|
133
|
+
error: string | null;
|
|
134
|
+
}
|
|
135
|
+
/** Fixtures written by scripts/chat-format-goldens.py from transformers at a pinned repository revision. */
|
|
136
|
+
interface ChatFormatGoldens {
|
|
137
|
+
repository: string;
|
|
138
|
+
revision: string;
|
|
139
|
+
transformers: string;
|
|
140
|
+
/** sha256 of each repository file the reference read. */
|
|
141
|
+
files: Record<string, string>;
|
|
142
|
+
/** The special tokens transformers passed to the template. */
|
|
143
|
+
variables: Record<string, unknown>;
|
|
144
|
+
cases: ChatFormatGoldenCase[];
|
|
145
|
+
}
|
|
146
|
+
/** A chat format package, as goldens invoke it. */
|
|
147
|
+
interface ChatFormatGoldenTarget {
|
|
148
|
+
invoke(request: {
|
|
149
|
+
resource: {
|
|
150
|
+
crn: string;
|
|
151
|
+
hash: string;
|
|
152
|
+
kind: "service";
|
|
153
|
+
};
|
|
154
|
+
op: string;
|
|
155
|
+
args: unknown;
|
|
156
|
+
idempotencyKey: string;
|
|
157
|
+
handleId: null;
|
|
158
|
+
}, context: ChatAssetLoader & {
|
|
159
|
+
config: unknown;
|
|
160
|
+
}): Promise<unknown>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Checks a chat format against goldens: each case renders to exactly the reference tokens, spans and stop tokens (or
|
|
164
|
+
* fails as the reference did), and parsing each trained span gives back its message's content, Tool calls (by name
|
|
165
|
+
* and arguments) and reasoning, stopped. Returns one line per mismatch; empty when the format matches.
|
|
166
|
+
*/
|
|
167
|
+
declare function chatFormatGoldens(format: ChatFormatGoldenTarget, goldens: ChatFormatGoldens, context: ChatAssetLoader & {
|
|
168
|
+
config: unknown;
|
|
169
|
+
}): Promise<string[]>;
|
|
170
|
+
|
|
171
|
+
export { NotAppendOnly, chatFormatGoldens, chatSpans, chatTokenizer, loadChatTokenizer, renderChatTemplate };
|
|
172
|
+
export type { ChatAssetLoader, ChatFormatGoldenCase, ChatFormatGoldenTarget, ChatFormatGoldens, ChatSpanFormat, ChatTemplateInput, ChatTokenizer };
|