@constal/sdk 5.3.0 → 6.1.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 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": "5.3.0",
3
+ "version": "6.1.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": "5.3.0",
3
+ "version": "6.1.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",
@@ -196,6 +209,7 @@
196
209
  "Handle",
197
210
  "HandleOutcome",
198
211
  "Hash",
212
+ "HistoryPage",
199
213
  "HistoryView",
200
214
  "HmacVerification",
201
215
  "IgnoredChannelEvent",
@@ -272,6 +286,7 @@
272
286
  "ModelTool",
273
287
  "NondeterministicReplay",
274
288
  "NormalizedModelGatewayConfig",
289
+ "NotAppendOnly",
275
290
  "NoulAnswer",
276
291
  "NoulQuestion",
277
292
  "Out",
@@ -394,6 +409,23 @@
394
409
  "SetupSubmission",
395
410
  "SetupTerminalPanel",
396
411
  "SetupWorkflowStatus",
412
+ "Share",
413
+ "ShareAction",
414
+ "ShareContribution",
415
+ "ShareContributionImport",
416
+ "ShareContributionRequest",
417
+ "ShareContributionReview",
418
+ "ShareContributionReviewRequest",
419
+ "ShareContributionStatus",
420
+ "ShareEvaluation",
421
+ "ShareEvaluationPin",
422
+ "ShareEvaluationRequest",
423
+ "ShareEvaluationVerdict",
424
+ "ShareEvaluationView",
425
+ "ShareHistory",
426
+ "SharePrice",
427
+ "ShareRequest",
428
+ "ShareReviewDecision",
397
429
  "Skill",
398
430
  "SkillDescription",
399
431
  "SkillLibrary",
@@ -409,9 +441,11 @@
409
441
  "StageOutputSpec",
410
442
  "StartTrainingRequest",
411
443
  "SteerEvent",
444
+ "StepJournal",
412
445
  "SuiteFact",
413
446
  "SwallowedYield",
414
447
  "TRAINING_PROVIDER_CAPABILITY",
448
+ "TRAINING_RECIPE_DEFAULTS",
415
449
  "TableAggregate",
416
450
  "TableDescribeArgs",
417
451
  "TableFilter",
@@ -428,17 +462,20 @@
428
462
  "Tool",
429
463
  "ToolCallRecord",
430
464
  "ToolUnavailable",
465
+ "TrainingCorrection",
431
466
  "TrainingJobFact",
432
467
  "TrainingJobReference",
433
468
  "TrainingJobState",
434
469
  "TrainingJobStatus",
435
470
  "TrainingMethod",
436
471
  "TrainingModelOffer",
472
+ "TrainingPreparation",
437
473
  "TrainingProviderDefinition",
438
474
  "TrainingProviderMetadata",
439
475
  "TrainingProviderPin",
440
476
  "TrainingRecipe",
441
477
  "TrainingResumePoint",
478
+ "TrainingStep",
442
479
  "TrainingUsageUnits",
443
480
  "TurnDraft",
444
481
  "TurnGate",
@@ -493,6 +530,14 @@
493
530
  "channelSourceEvidence",
494
531
  "channelSubscriptionRequest",
495
532
  "channelTarget",
533
+ "chatFormat",
534
+ "chatFormatMetadata",
535
+ "chatFormatPin",
536
+ "chatParseInput",
537
+ "chatParsed",
538
+ "chatRenderInput",
539
+ "chatRenderRequest",
540
+ "chatRendering",
496
541
  "checkpointArtifactRef",
497
542
  "checkpointDeploymentRequest",
498
543
  "checkpointImportMetadata",
@@ -515,6 +560,7 @@
515
560
  "customerTenantName",
516
561
  "cutBatches",
517
562
  "cutPartitions",
563
+ "dataShareEarningMicroUsd",
518
564
  "datasetName",
519
565
  "evaluateCodeScorer",
520
566
  "evaluatePolicyDefinition",
@@ -562,7 +608,6 @@
562
608
  "policy",
563
609
  "policyName",
564
610
  "race",
565
- "renderTrainingCompletion",
566
611
  "resolveBindingOwner",
567
612
  "resolveContainerImageSource",
568
613
  "resolveGatewayEgress",
@@ -576,6 +621,7 @@
576
621
  "resourcePattern",
577
622
  "resourceSelector",
578
623
  "resourceTools",
624
+ "runLabels",
579
625
  "sandboxControls",
580
626
  "sandboxEgressDecision",
581
627
  "sandboxEgressHostMatches",
@@ -594,12 +640,18 @@
594
640
  "setupScreenView",
595
641
  "setupSubmission",
596
642
  "sha256Hex",
643
+ "shareContributionRequest",
644
+ "shareContributionReview",
645
+ "shareEvaluation",
646
+ "sharePrices",
647
+ "shareRequest",
597
648
  "skills",
598
649
  "stageOutput",
599
650
  "startTrainingRequest",
600
651
  "subtask",
601
652
  "tableDescribe",
602
653
  "tableQuery",
654
+ "trainingCorrection",
603
655
  "trainingProvider",
604
656
  "trainingProviderMetadata",
605
657
  "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 };