@constal/sdk 3.1.0 → 3.3.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/README.md CHANGED
@@ -30,52 +30,196 @@ 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:
61
+
62
+ ```ts
63
+ await ctx.invoke(ctx.resources.service!, "read", { id: "requested-object" }, {
64
+ credentials: {
65
+ account: { kind: "scoped", key: "service-account", owner: "principal", required: true },
66
+ },
67
+ });
68
+ ```
69
+
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:
34
113
 
35
114
  ```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
- });
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
+ },
77
129
  },
78
130
  });
79
131
  ```
80
132
 
81
- See the [Constal documentation](https://constal.ai/docs) for package manifests and deployment workflows.
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
+ ## Execution images
188
+
189
+ Import an existing image through the bound SandboxPool:
190
+
191
+ ```ts
192
+ const pool = ctx.sandboxPool(ctx.resources.sandbox!);
193
+ const image = await pool.importImage({ reference: "registry.example.com/team/tests:v1" });
194
+ const workspace = await pool.createSandbox(ctx.run.agent.crn, ctx.run.session, { image });
195
+ ```
196
+
197
+ Imported handles expose `image.source`, including the resolved OCI reference and
198
+ manifest digest. The pool owns provider registration, reuse, and deletion.
199
+ `importSandboxImageInput(value)` validates configuration inputs.
200
+
201
+ Private registries accept `registry: { username, credential }`. The provider
202
+ adapter supplies any required runtime preparation; the same sandbox Driver executes
203
+ it with normal policy, credential delivery, usage, and cancellation. Blaxel images
204
+ receive the sandbox API. Private Daytona images are prepared in the provider
205
+ registry using temporary, scoped push access.
206
+
207
+ Set `cache: false` to request a fresh import. Reuse still checks current source
208
+ access and provider readiness. Image deletion does not delete running sandboxes.
209
+
210
+ Build a working directory with the same sandbox:
211
+
212
+ ```ts
213
+ const built = await workspace.buildImage({
214
+ context: "/workspace/repo",
215
+ dockerfile: "Dockerfile",
216
+ }, { timeoutMs: 900_000 });
217
+ ```
218
+
219
+ The sandbox image supplies Docker, Buildx, regctl, and Python. The operation uses normal
220
+ Sandbox Driver execution, policy, credentials, cancellation, and billing. It
221
+ returns a command result with an `image` receipt on successful publication.
222
+ `stderrRef` retains the build log and `image.metadata` retains BuildKit metadata.
223
+ Build secrets and private registries take Credential references, not values.
224
+ `cache: false` disables registry cache; credential rotation changes cache variants.
225
+ 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.1.0",
3
+ "version": "3.3.0",
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.1.0",
3
+ "version": "3.3.0",
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,8 @@
90
96
  "ConstalApiChangePlanRequest",
91
97
  "ConstalApiChangeReceipt",
92
98
  "ConstalApiOperationReceipt",
99
+ "ConstalApiQueryResult",
100
+ "ContainerImageSource",
93
101
  "ControlEvent",
94
102
  "Cost",
95
103
  "CreateSandboxImageOptions",
@@ -145,6 +153,7 @@
145
153
  "FixedMemoryStoreRef",
146
154
  "FixedModelGatewayRef",
147
155
  "FoldFn",
156
+ "GATEWAY_MODEL_OFFER_SCHEMA",
148
157
  "GateEvidence",
149
158
  "GateExhausted",
150
159
  "GateResult",
@@ -159,6 +168,7 @@
159
168
  "GatewayOperation",
160
169
  "GatewayPackage",
161
170
  "GatewayPackageMetadata",
171
+ "GatewayPackageRef",
162
172
  "GatewayRecoveryRequest",
163
173
  "GatewayRecoveryResult",
164
174
  "GatewayRequest",
@@ -168,6 +178,7 @@
168
178
  "Hash",
169
179
  "HistoryView",
170
180
  "IgnoredChannelEvent",
181
+ "ImportSandboxImageInput",
171
182
  "IngressRequest",
172
183
  "IngressTarget",
173
184
  "IntegrationArtifactEgressRequest",
@@ -180,6 +191,7 @@
180
191
  "IntegrationRequestNotSent",
181
192
  "IntegrationSecret",
182
193
  "IntegrationState",
194
+ "InvocationHandle",
183
195
  "InvokableKind",
184
196
  "InvokeOpts",
185
197
  "JsonScalar",
@@ -191,14 +203,19 @@
191
203
  "LeaseLost",
192
204
  "LedgerAddress",
193
205
  "LedgerEvent",
206
+ "LoadedSkill",
194
207
  "LocalResourceRef",
195
208
  "MCP_CLIENT_CAPABILITY",
196
209
  "MEMORY_OPERATION_DECLARATIONS",
197
210
  "MODEL_CHECKPOINT_IMPORT_CAPABILITY",
198
211
  "MODEL_COMPLETION_CAPABILITY",
212
+ "MODEL_GENERATION_OPTIONS_SCHEMA",
213
+ "MODEL_GENERATION_OPTION_KEYS",
199
214
  "ManifestIndexPage",
200
215
  "MapFact",
201
216
  "MapOpts",
217
+ "McpMessage",
218
+ "McpTool",
202
219
  "MemoryDeleteArgs",
203
220
  "MemoryGetArgs",
204
221
  "MemoryRecord",
@@ -208,10 +225,12 @@
208
225
  "MemoryStoreBinding",
209
226
  "Mode",
210
227
  "ModelAdvertisedPricing",
228
+ "ModelCompletion",
211
229
  "ModelCredentialHeader",
212
230
  "ModelGatewayBinding",
213
231
  "ModelGatewayConfig",
214
232
  "ModelGatewayProtocol",
233
+ "ModelGenerationOptions",
215
234
  "ModelGovernanceControls",
216
235
  "ModelGovernanceMeter",
217
236
  "ModelInvocationArgs",
@@ -237,7 +256,9 @@
237
256
  "PolicyOutcome",
238
257
  "Principal",
239
258
  "PrincipalKind",
259
+ "ProcessConnection",
240
260
  "Provenance",
261
+ "RESOURCE_CREDENTIAL_BINDING_SCHEMA",
241
262
  "RESOURCE_KINDS",
242
263
  "RawModelProtocol",
243
264
  "Recovery",
@@ -245,6 +266,7 @@
245
266
  "ReduceOpts",
246
267
  "Ref",
247
268
  "RequestLabelRequest",
269
+ "ResourceConnectionAttempt",
248
270
  "ResourceContractRef",
249
271
  "ResourceControlsConstraint",
250
272
  "ResourceCredentialBinding",
@@ -255,26 +277,38 @@
255
277
  "ResourceName",
256
278
  "ResourceNameParts",
257
279
  "ResourceNeed",
280
+ "ResourceOperation",
258
281
  "ResourcePattern",
259
282
  "ResourceSelector",
260
283
  "ResourceUnbound",
261
284
  "RollbackReport",
262
285
  "RollbackTargetInvalid",
286
+ "RunCapabilities",
263
287
  "RunIdentityView",
264
288
  "RunInfo",
265
289
  "RunStatusDetail",
266
290
  "RunSuiteRequest",
291
+ "SANDBOX_PROCESS_CREDENTIALS_SCHEMA",
267
292
  "Sandbox",
268
293
  "SandboxCommandResult",
294
+ "SandboxCredentialTargets",
269
295
  "SandboxExecInput",
270
296
  "SandboxFileResult",
271
297
  "SandboxGovernanceControls",
272
298
  "SandboxGovernanceMeter",
273
299
  "SandboxImage",
300
+ "SandboxImageBuildInput",
301
+ "SandboxImageBuildResult",
274
302
  "SandboxMutationResult",
275
303
  "SandboxNetworkMode",
276
304
  "SandboxNetworkPolicy",
277
305
  "SandboxPool",
306
+ "SandboxProcess",
307
+ "SandboxProcessCredentials",
308
+ "SandboxProcessReadOptions",
309
+ "SandboxProcessReadResult",
310
+ "SandboxProcessWriteInput",
311
+ "SandboxProcessWriteResult",
278
312
  "SandboxReadFileOptions",
279
313
  "SandboxReadFileResult",
280
314
  "SandboxWriteFileResult",
@@ -296,6 +330,7 @@
296
330
  "SetupAction",
297
331
  "SetupCredentialCandidate",
298
332
  "SetupCredentialInteractionPanel",
333
+ "SetupCredentialReceipt",
299
334
  "SetupFormPanel",
300
335
  "SetupPanel",
301
336
  "SetupProgressPanel",
@@ -306,6 +341,10 @@
306
341
  "SetupSubmission",
307
342
  "SetupTerminalPanel",
308
343
  "SetupWorkflowStatus",
344
+ "Skill",
345
+ "SkillDescription",
346
+ "SkillSet",
347
+ "SkillSource",
309
348
  "SortField",
310
349
  "SpawnAttenuation",
311
350
  "SpawnBudget",
@@ -380,6 +419,7 @@
380
419
  "agentSetupMetadata",
381
420
  "agentSetupRequirements",
382
421
  "analyticsEvent",
422
+ "applyModelProviderOptions",
383
423
  "approximateTokens",
384
424
  "authProvider",
385
425
  "authProviderName",
@@ -399,6 +439,7 @@
399
439
  "checkpointImportMetadata",
400
440
  "checkpointImportRequest",
401
441
  "codeScorerIR",
442
+ "connections",
402
443
  "credentialEvidence",
403
444
  "credentialInteractionAction",
404
445
  "credentialInteractionEvent",
@@ -421,23 +462,29 @@
421
462
  "gatewayPackageMetadata",
422
463
  "hash",
423
464
  "hashValue",
465
+ "importSandboxImageInput",
424
466
  "integrationEgressPolicy",
425
467
  "labelSelector",
426
468
  "matchesAction",
427
469
  "matchesLabelSelector",
428
470
  "matchesResource",
471
+ "mcpProtocol",
429
472
  "memoryStoreBinding",
430
473
  "modelAdvertisedPricing",
431
474
  "modelControls",
432
475
  "modelGatewayBinding",
433
476
  "modelGatewayEndpoint",
477
+ "modelGenerationOptions",
434
478
  "modelLimit",
435
479
  "modelPrompt",
436
480
  "modelProtocolRequest",
437
481
  "modelProtocolResult",
482
+ "modelProviderOptions",
438
483
  "murmur3_32",
484
+ "normalizeInvocationOptions",
439
485
  "normalizeModelGatewayConfig",
440
486
  "normalizeSandboxNetworkPolicy",
487
+ "normalizeSandboxWorkspacePath",
441
488
  "opTool",
442
489
  "opTools",
443
490
  "parseResourceName",
@@ -447,26 +494,34 @@
447
494
  "resolveBindingOwner",
448
495
  "resolveGatewayEgress",
449
496
  "resolveResourceDependencyRef",
497
+ "resourceContext",
450
498
  "resourceContractRef",
451
499
  "resourceCredentialBinding",
500
+ "resourceCredentialBindings",
452
501
  "resourceDependencyRef",
502
+ "resourceIndex",
453
503
  "resourceLabelMap",
454
504
  "resourceName",
455
505
  "resourceNeed",
456
506
  "resourcePattern",
457
507
  "resourceSelector",
508
+ "resourceTools",
458
509
  "sandboxControls",
510
+ "sandboxImageBuildInput",
459
511
  "sandboxLimit",
512
+ "sandboxProcessCredentials",
460
513
  "scopedBindingKey",
461
514
  "scopedCredentialRef",
462
515
  "scopedResourceRef",
463
516
  "scorerName",
464
517
  "selectableResourceLabels",
465
518
  "setupAwait",
519
+ "setupCredentialReceipt",
466
520
  "setupScreen",
467
521
  "setupScreenView",
468
522
  "setupSubmission",
469
523
  "sha256Hex",
524
+ "skills",
470
525
  "stageOutput",
471
526
  "startTrainingRequest",
472
527
  "subtask",