@constal/sdk 3.2.0 → 3.3.1

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 CHANGED
@@ -30,52 +30,175 @@ Connection code receives `GatewayContext`/`IntegrationContext`: declared Credent
30
30
 
31
31
  `gateway(...)` and `credentialProvider(...)` return validated packages suitable for managed deployment. Users implement the package contract; Constal supplies its execution environment.
32
32
 
33
- ## Example Connection
33
+ ## Skills and Resource discovery
34
+
35
+ These additions are implemented locally and await SDK/runtime release integration.
36
+
37
+ `skills(...)` accepts supplied instructions or a caller-owned `list`/`load`
38
+ source. Its `list_skills` and `read_skill` Tools can be registered in an Agent's
39
+ normal tool map. The SDK does not scan a repository or select skills for the model.
40
+
41
+ `ctx.capabilities()` returns a copy of the Run's pinned Resource and Tool
42
+ contracts, including identities, schemas, effects, and asynchronous operation
43
+ metadata. It excludes private resource configuration, credentials, and operations
44
+ that are not public Agent capabilities. Reading it performs no network request.
45
+
46
+ `resourceIndex(ctx)` produces a complete binding/operation index for model
47
+ context. Use `await resourceContext(ctx)` when supplying that context to a model
48
+ turn: it journals the index and Run identity through `ctx.step`, so old turns
49
+ replay with their original capabilities while later turns can observe new
50
+ bindings. Call it for each turn whose context should reflect current bindings.
51
+ Opt into `resourceTools` in the Agent's normal tool map to offer
52
+ `resource_list`, `resource_describe`, and `resource_invoke`. Invocation uses the
53
+ existing `ctx.invoke` or `ctx.invokeAsync` path according to the pinned operation
54
+ contract; Policy, credential resolution, recovery, and journals still apply.
55
+ The catalog includes the consuming adapter's credential slot names, without
56
+ exposing its configured credential references or values. Catalog availability does not promise that a particular attempted invocation
57
+ will be authorized or that an external connection will succeed.
58
+
59
+ An invocation can select existing credentials for adapter slots through
60
+ `InvokeOpts.credentials`, using Credential CRNs or scoped credential references:
34
61
 
35
62
  ```ts
36
- import { gateway } from "@constal/sdk";
37
-
38
- export default gateway({
39
- id: "ticket-connection",
40
- version: "1.0.0",
41
- kind: "service",
42
- displayName: "Ticket connection",
43
- description: "Read tickets from the configured account.",
44
- credentialSlots: { account: { title: "Account Credential" } },
45
- capabilities: [{
46
- id: "example.ticket-read",
47
- version: "1",
48
- hash: "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
49
- }],
50
- billing: { upstreamPayer: "tenant" },
51
- configSchema: { type: "object", additionalProperties: false },
52
- egress: { rules: [{
53
- operations: ["ticket.get"],
54
- origin: "https://api.example.com",
55
- pathPrefix: "/tickets/",
56
- methods: ["GET"],
57
- }] },
58
- catalog: () => [{
59
- op: "ticket.get",
60
- description: "Read one ticket.",
61
- schema: { type: "object" },
62
- resultSchema: { type: "object" },
63
- effect: "read-only",
64
- recovery: { kind: "repeat" },
65
- async: false,
66
- usage: { meter: "none", priceTable: null },
67
- }],
68
- async invoke(request, context) {
69
- const credential = await context.secret("account");
70
- return context.egress({
71
- url: `https://api.example.com/tickets/${encodeURIComponent(String((request.args as { id: string }).id))}`,
72
- method: "GET",
73
- headers: { authorization: `Bearer ${credential.value}` },
74
- maximumResponseBytes: 1_048_576,
75
- maximumRedirects: 0,
76
- });
63
+ await ctx.invoke(ctx.resources.service!, "read", { id: "requested-object" }, {
64
+ credentials: {
65
+ account: { kind: "scoped", key: "service-account", owner: "principal", required: true },
77
66
  },
78
67
  });
79
68
  ```
80
69
 
81
- See the [Constal documentation](https://constal.ai/docs) for package manifests and deployment workflows.
70
+ `resource_invoke` accepts the same optional `credentials` map. The platform
71
+ resolves it through the existing binding registry and retains the selected
72
+ references with that invocation. Unselected slots and the stored Resource stay
73
+ unchanged. The adapter's normal `context.secret(slot)` call applies credential-use
74
+ Policy and reads current material through the existing credential lifecycle.
75
+ Per-process environment/file injection is not implemented by this option alone.
76
+
77
+ ## Persistent sandbox processes
78
+
79
+ `Sandbox.startProcess(...)` submits an interactive command and returns a process
80
+ handle while the command continues running. It accepts the same environment and
81
+ credential references as `Sandbox.exec(...)`. Reuse `sandbox.process(id)` within
82
+ the originating Run to read, write, or stop an existing process.
83
+
84
+ ```ts
85
+ const process = await workspace.startProcess({ cmd: "node", args: ["server.js"] });
86
+ await process.write({ data: "request\n" });
87
+ const page = await process.read({ stream: "stdout", offset: 0 });
88
+ // Consume further pages using page.nextOffset and the server's message framing.
89
+ await process.stop();
90
+ ```
91
+
92
+ Reads return base64 bytes, offsets, the current output length, and child exit
93
+ state. A running child can return an empty page. Each response contains at most
94
+ 64 KiB; the complete output remains available through subsequent ranges until
95
+ the command stops. Join bytes before decoding text that spans ranges. Writes
96
+ accept UTF-8 text or explicit base64 and can close stdin after the write with
97
+ `close: true`. Retrying an invocation does not repeat its input write.
98
+
99
+ The original execution invocation owns credentials, timeout, usage, and Run
100
+ cleanup. The SDK reuses `ctx.invokeAsync(...).start()` to submit without waiting
101
+ for completion; awaiting the Handle still waits for its result. For model-facing
102
+ Resource Tools, `resource_invoke` accepts `wait: false` on asynchronous operations
103
+ and returns a submitted Handle ID. Submission does not prove process readiness
104
+ or successful connection. Normal Policy and credential resolution still apply.
105
+
106
+ These APIs are implemented locally and require coordinated SDK/runtime/Driver
107
+ release. Live-provider validation remains open.
108
+
109
+ ## Local MCP connections
110
+
111
+ The opt-in `connections(...)` adapter accepts a process definition as well as
112
+ remote Gateway definitions and existing bindings:
113
+
114
+ ```ts
115
+ import { connections } from "@constal/sdk";
116
+
117
+ const configured = connections({
118
+ project: {
119
+ process: {
120
+ pool: "crn:constal:production:tenant:default:sandbox-pool/execution",
121
+ command: {
122
+ cmd: "node",
123
+ args: ["tools/mcp-server.mjs"],
124
+ cwd: "/workspace/repo",
125
+ timeoutMs: 1_800_000,
126
+ },
127
+ requestTimeoutMs: 60_000,
128
+ },
129
+ },
130
+ });
131
+ ```
132
+
133
+ Register `configured.tools` and `configured.views` in the Agent definition, and
134
+ use `await configured.index(ctx)` when supplying connection facts to the model.
135
+ The server executable and its dependencies must exist in the selected sandbox.
136
+ Process settings use the normal SDK command contract, including Credential
137
+ references for env/file delivery. No repository convention is built into this
138
+ adapter.
139
+
140
+ `connection_invoke` accepts a connection name, operation, and arguments. It
141
+ connects when needed, discovers the server's tools, and reuses the process across
142
+ calls in that Run. `connection_connect` can explicitly refresh the catalog or
143
+ restart a healthy process. A failed attempt returns its observed failure; a
144
+ later request can reconnect. `connection_disconnect` stops a local process.
145
+ Remote operations use their existing Resource bindings and invocation path.
146
+ Their latest explicit connection attempt is retained in the same view, including
147
+ installation or attachment failures. `index(ctx)` reports that attempt alongside
148
+ the current binding state, so an earlier failure cannot hide a Resource that is
149
+ now bound. Listing does not connect or retry. Observations belong to the current
150
+ Run and configured binding.
151
+
152
+ The client preserves MCP content blocks and structured content. Request timeouts
153
+ do not automatically restart the server or resend the action. Late responses
154
+ encountered by a subsequent call appear in its `_meta` under
155
+ `ai.constal/earlierResponses`. Malformed or closed streams are reported as
156
+ connection failures. Empty reads use the runtime's existing timed waits without
157
+ a conversational presentation. Catalogs are stored once when discovered;
158
+ ordinary calls record protocol progress through the same ledger.
159
+
160
+ The HTTP Gateway and local adapter share protocol parsing, initialization, and
161
+ tool discovery. Local stdio follows the
162
+ [MCP transport contract](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports).
163
+ Sampling, elicitation, and roots are not advertised as client capabilities.
164
+ This local implementation is unreleased; full live-provider validation remains
165
+ pending.
166
+
167
+ ## Model generation settings
168
+
169
+ `ctx.turn` accepts `effort`, `temperature`, `maxOutputTokens`, and optional
170
+ `providerOptions`. The same generation contract is used by Model resource
171
+ defaults. Omitted settings retain their configured defaults, and explicit
172
+ per-turn choices are included in invocation and replay identity.
173
+
174
+ `providerOptions` supplies additional fields in the selected upstream API's
175
+ format, such as `top_p`. Constal Gateway applies these after protocol translation.
176
+ They cannot replace the model, prompt, Tools, streaming mode, or common generation
177
+ controls. The selected adapter/provider reports unsupported values. Model-output
178
+ limits apply to completions; they do not truncate stored evidence.
179
+
180
+ `CONSTAL_MODEL_CREATE_SCHEMA` describes the HTTP Model creation body and the
181
+ native API's `model.create.model` payload. The new Resource's `id` is separate
182
+ from the upstream model selected by `offer`. Advertised offers use
183
+ `{ kind: "advertised", modelId }`; manual offers use
184
+ `{ kind: "manual", model }`, with metadata described by
185
+ `GATEWAY_MODEL_OFFER_SCHEMA`. Generation settings go in `defaults`.
186
+
187
+ ## Building images
188
+
189
+ Build and publish a working directory through the bound sandbox:
190
+
191
+ ```ts
192
+ const built = await workspace.buildImage({
193
+ context: "/workspace/repo",
194
+ dockerfile: "Dockerfile",
195
+ }, { timeoutMs: 900_000 });
196
+ ```
197
+
198
+ The sandbox image supplies Docker, Buildx, regctl, and Python. The operation uses normal
199
+ Sandbox Driver execution, policy, credentials, cancellation, and billing. It
200
+ returns a command result with an `image` receipt on successful publication.
201
+ `stderrRef` retains the build log and `image.metadata` retains BuildKit metadata.
202
+ Build secrets and private registries take Credential references, not values.
203
+ `cache: false` disables registry cache; credential rotation changes cache variants.
204
+ The standalone image-builder service is not part of this API.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constal/sdk",
3
- "version": "3.2.0",
3
+ "version": "3.3.1",
4
4
  "description": "Public TypeScript SDK for authoring Constal agents, integrations, policies, channels, and credential providers",
5
5
  "keywords": [
6
6
  "constal",
@@ -33,9 +33,10 @@
33
33
  "build": "node ../../scripts/build-sdk-boundaries.mjs --public-only",
34
34
  "test": "vitest run test",
35
35
  "typecheck": "tsc -b --pretty false",
36
- "prepack": "npm run typecheck && npm test && npm run build"
36
+ "prepack": "npm run typecheck && npm run build && npm test"
37
37
  },
38
38
  "devDependencies": {
39
+ "@noble/hashes": "^2.0.1",
39
40
  "esbuild": "^0.28.2",
40
41
  "rollup": "^4.62.4",
41
42
  "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.2.0",
3
+ "version": "3.3.1",
4
4
  "exports": [
5
5
  "Action",
6
6
  "ActionPattern",
@@ -11,6 +11,7 @@
11
11
  "AdmissionLimitWindow",
12
12
  "AfterYield",
13
13
  "Agent",
14
+ "AgentConnection",
14
15
  "AgentCredentialSetupRequirement",
15
16
  "AgentDef",
16
17
  "AgentDeployPolicy",
@@ -34,6 +35,7 @@
34
35
  "BindingCRN",
35
36
  "BindingOwnerContext",
36
37
  "BindingOwnerScope",
38
+ "BoundResourceCapabilities",
37
39
  "BranchRef",
38
40
  "CONSTAL_API_CAPABILITY",
39
41
  "CONSTAL_API_GET_KINDS",
@@ -42,6 +44,7 @@
42
44
  "CONSTAL_API_OPERATION_SCHEMAS",
43
45
  "CONSTAL_API_QUERY_KINDS",
44
46
  "CONSTAL_API_VERSION",
47
+ "CONSTAL_MODEL_CREATE_SCHEMA",
45
48
  "CRN",
46
49
  "CRNKind",
47
50
  "CanonicalEvent",
@@ -78,11 +81,14 @@
78
81
  "CompareSuitesRequest",
79
82
  "Compensation",
80
83
  "ConnectionCancelRequest",
84
+ "ConnectionDescription",
81
85
  "ConnectionIdentity",
82
86
  "ConnectionOperation",
83
87
  "ConnectionRecoveryRequest",
84
88
  "ConnectionRecoveryResult",
85
89
  "ConnectionRequest",
90
+ "ConnectionSource",
91
+ "ConnectionStatus",
86
92
  "ConnectionUsageReport",
87
93
  "ConstalApiApplyRequest",
88
94
  "ConstalApiChangePlan",
@@ -90,6 +96,7 @@
90
96
  "ConstalApiChangePlanRequest",
91
97
  "ConstalApiChangeReceipt",
92
98
  "ConstalApiOperationReceipt",
99
+ "ConstalApiQueryResult",
93
100
  "ControlEvent",
94
101
  "Cost",
95
102
  "CreateSandboxImageOptions",
@@ -145,6 +152,7 @@
145
152
  "FixedMemoryStoreRef",
146
153
  "FixedModelGatewayRef",
147
154
  "FoldFn",
155
+ "GATEWAY_MODEL_OFFER_SCHEMA",
148
156
  "GateEvidence",
149
157
  "GateExhausted",
150
158
  "GateResult",
@@ -159,6 +167,7 @@
159
167
  "GatewayOperation",
160
168
  "GatewayPackage",
161
169
  "GatewayPackageMetadata",
170
+ "GatewayPackageRef",
162
171
  "GatewayRecoveryRequest",
163
172
  "GatewayRecoveryResult",
164
173
  "GatewayRequest",
@@ -180,6 +189,7 @@
180
189
  "IntegrationRequestNotSent",
181
190
  "IntegrationSecret",
182
191
  "IntegrationState",
192
+ "InvocationHandle",
183
193
  "InvokableKind",
184
194
  "InvokeOpts",
185
195
  "JsonScalar",
@@ -191,14 +201,19 @@
191
201
  "LeaseLost",
192
202
  "LedgerAddress",
193
203
  "LedgerEvent",
204
+ "LoadedSkill",
194
205
  "LocalResourceRef",
195
206
  "MCP_CLIENT_CAPABILITY",
196
207
  "MEMORY_OPERATION_DECLARATIONS",
197
208
  "MODEL_CHECKPOINT_IMPORT_CAPABILITY",
198
209
  "MODEL_COMPLETION_CAPABILITY",
210
+ "MODEL_GENERATION_OPTIONS_SCHEMA",
211
+ "MODEL_GENERATION_OPTION_KEYS",
199
212
  "ManifestIndexPage",
200
213
  "MapFact",
201
214
  "MapOpts",
215
+ "McpMessage",
216
+ "McpTool",
202
217
  "MemoryDeleteArgs",
203
218
  "MemoryGetArgs",
204
219
  "MemoryRecord",
@@ -208,10 +223,12 @@
208
223
  "MemoryStoreBinding",
209
224
  "Mode",
210
225
  "ModelAdvertisedPricing",
226
+ "ModelCompletion",
211
227
  "ModelCredentialHeader",
212
228
  "ModelGatewayBinding",
213
229
  "ModelGatewayConfig",
214
230
  "ModelGatewayProtocol",
231
+ "ModelGenerationOptions",
215
232
  "ModelGovernanceControls",
216
233
  "ModelGovernanceMeter",
217
234
  "ModelInvocationArgs",
@@ -237,7 +254,9 @@
237
254
  "PolicyOutcome",
238
255
  "Principal",
239
256
  "PrincipalKind",
257
+ "ProcessConnection",
240
258
  "Provenance",
259
+ "RESOURCE_CREDENTIAL_BINDING_SCHEMA",
241
260
  "RESOURCE_KINDS",
242
261
  "RawModelProtocol",
243
262
  "Recovery",
@@ -245,6 +264,7 @@
245
264
  "ReduceOpts",
246
265
  "Ref",
247
266
  "RequestLabelRequest",
267
+ "ResourceConnectionAttempt",
248
268
  "ResourceContractRef",
249
269
  "ResourceControlsConstraint",
250
270
  "ResourceCredentialBinding",
@@ -255,26 +275,38 @@
255
275
  "ResourceName",
256
276
  "ResourceNameParts",
257
277
  "ResourceNeed",
278
+ "ResourceOperation",
258
279
  "ResourcePattern",
259
280
  "ResourceSelector",
260
281
  "ResourceUnbound",
261
282
  "RollbackReport",
262
283
  "RollbackTargetInvalid",
284
+ "RunCapabilities",
263
285
  "RunIdentityView",
264
286
  "RunInfo",
265
287
  "RunStatusDetail",
266
288
  "RunSuiteRequest",
289
+ "SANDBOX_PROCESS_CREDENTIALS_SCHEMA",
267
290
  "Sandbox",
268
291
  "SandboxCommandResult",
292
+ "SandboxCredentialTargets",
269
293
  "SandboxExecInput",
270
294
  "SandboxFileResult",
271
295
  "SandboxGovernanceControls",
272
296
  "SandboxGovernanceMeter",
273
297
  "SandboxImage",
298
+ "SandboxImageBuildInput",
299
+ "SandboxImageBuildResult",
274
300
  "SandboxMutationResult",
275
301
  "SandboxNetworkMode",
276
302
  "SandboxNetworkPolicy",
277
303
  "SandboxPool",
304
+ "SandboxProcess",
305
+ "SandboxProcessCredentials",
306
+ "SandboxProcessReadOptions",
307
+ "SandboxProcessReadResult",
308
+ "SandboxProcessWriteInput",
309
+ "SandboxProcessWriteResult",
278
310
  "SandboxReadFileOptions",
279
311
  "SandboxReadFileResult",
280
312
  "SandboxWriteFileResult",
@@ -307,6 +339,10 @@
307
339
  "SetupSubmission",
308
340
  "SetupTerminalPanel",
309
341
  "SetupWorkflowStatus",
342
+ "Skill",
343
+ "SkillDescription",
344
+ "SkillSet",
345
+ "SkillSource",
310
346
  "SortField",
311
347
  "SpawnAttenuation",
312
348
  "SpawnBudget",
@@ -381,6 +417,7 @@
381
417
  "agentSetupMetadata",
382
418
  "agentSetupRequirements",
383
419
  "analyticsEvent",
420
+ "applyModelProviderOptions",
384
421
  "approximateTokens",
385
422
  "authProvider",
386
423
  "authProviderName",
@@ -400,6 +437,7 @@
400
437
  "checkpointImportMetadata",
401
438
  "checkpointImportRequest",
402
439
  "codeScorerIR",
440
+ "connections",
403
441
  "credentialEvidence",
404
442
  "credentialInteractionAction",
405
443
  "credentialInteractionEvent",
@@ -427,18 +465,23 @@
427
465
  "matchesAction",
428
466
  "matchesLabelSelector",
429
467
  "matchesResource",
468
+ "mcpProtocol",
430
469
  "memoryStoreBinding",
431
470
  "modelAdvertisedPricing",
432
471
  "modelControls",
433
472
  "modelGatewayBinding",
434
473
  "modelGatewayEndpoint",
474
+ "modelGenerationOptions",
435
475
  "modelLimit",
436
476
  "modelPrompt",
437
477
  "modelProtocolRequest",
438
478
  "modelProtocolResult",
479
+ "modelProviderOptions",
439
480
  "murmur3_32",
481
+ "normalizeInvocationOptions",
440
482
  "normalizeModelGatewayConfig",
441
483
  "normalizeSandboxNetworkPolicy",
484
+ "normalizeSandboxWorkspacePath",
442
485
  "opTool",
443
486
  "opTools",
444
487
  "parseResourceName",
@@ -448,16 +491,22 @@
448
491
  "resolveBindingOwner",
449
492
  "resolveGatewayEgress",
450
493
  "resolveResourceDependencyRef",
494
+ "resourceContext",
451
495
  "resourceContractRef",
452
496
  "resourceCredentialBinding",
497
+ "resourceCredentialBindings",
453
498
  "resourceDependencyRef",
499
+ "resourceIndex",
454
500
  "resourceLabelMap",
455
501
  "resourceName",
456
502
  "resourceNeed",
457
503
  "resourcePattern",
458
504
  "resourceSelector",
505
+ "resourceTools",
459
506
  "sandboxControls",
507
+ "sandboxImageBuildInput",
460
508
  "sandboxLimit",
509
+ "sandboxProcessCredentials",
461
510
  "scopedBindingKey",
462
511
  "scopedCredentialRef",
463
512
  "scopedResourceRef",
@@ -469,6 +518,7 @@
469
518
  "setupScreenView",
470
519
  "setupSubmission",
471
520
  "sha256Hex",
521
+ "skills",
472
522
  "stageOutput",
473
523
  "startTrainingRequest",
474
524
  "subtask",