@constal/sdk 3.3.1 → 3.5.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 +162 -146
- package/package.json +2 -3
- package/publish/api.json +66 -34
- package/publish/index.d.ts +528 -667
- package/publish/index.js +2250 -2303
package/README.md
CHANGED
|
@@ -30,175 +30,191 @@ 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
|
-
##
|
|
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:
|
|
33
|
+
## Example Connection
|
|
61
34
|
|
|
62
35
|
```ts
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
+
});
|
|
66
77
|
},
|
|
67
78
|
});
|
|
68
79
|
```
|
|
69
80
|
|
|
70
|
-
|
|
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.
|
|
81
|
+
## Accepted Resource contracts
|
|
76
82
|
|
|
77
|
-
|
|
83
|
+
```ts
|
|
84
|
+
const bindings = Object.keys(ctx.resources);
|
|
85
|
+
const model = await ctx.describeResource("model");
|
|
86
|
+
const operations = (await ctx.describeResource("api"))?.operations;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The accessor records a local-step observation of one accepted Resource binding.
|
|
90
|
+
It requires no Resource or provider lookup. Replaying that position returns the
|
|
91
|
+
same observation; a later call can observe a safe-point binding update.
|
|
78
92
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
93
|
+
Results include public operation contracts, credential slot names, and advertised
|
|
94
|
+
metadata for pinned Models. They omit credential references/material, private
|
|
95
|
+
configuration, and control-plane operations. Returned objects are independent
|
|
96
|
+
copies. A configured operation is not a promise of authorization: Policy still
|
|
97
|
+
applies when it is invoked.
|
|
98
|
+
|
|
99
|
+
## Agent delivery
|
|
100
|
+
|
|
101
|
+
Bind another Agent Resource to the caller, then address that bound Agent by CRN:
|
|
83
102
|
|
|
84
103
|
```ts
|
|
85
|
-
const
|
|
86
|
-
await
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
await
|
|
104
|
+
const peer = ctx.resources.reviewer;
|
|
105
|
+
const receipt = await ctx.send(peer, { request: "Review this change" },
|
|
106
|
+
{ session: "review-123" });
|
|
107
|
+
|
|
108
|
+
const delivery = await ctx.send<{ verdict: string }>(peer,
|
|
109
|
+
{ request: "Review this change" }, { completion: "run-result" });
|
|
110
|
+
const answer = await delivery.result;
|
|
90
111
|
```
|
|
91
112
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
113
|
+
Each delivery queues a distinct Run in the target Agent's Session. Receipt mode
|
|
114
|
+
requires a Session and acknowledges the durable enqueue; result mode may omit
|
|
115
|
+
the Session to create a fresh one and returns a cancellable Handle for the target
|
|
116
|
+
Run's result. The target executes under the initiating principal's authority.
|
|
117
|
+
Policy evaluates `agent:invoke` on the exact bound target for each new send, and
|
|
118
|
+
the platform rechecks that authority when the target accepts the message.
|
|
119
|
+
Session and Run reads remain separate Policy actions. `ctx.commit` continues to
|
|
120
|
+
address the caller's own ledger.
|
|
98
121
|
|
|
99
|
-
|
|
100
|
-
|
|
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.
|
|
122
|
+
For model-selected operations, add the optional `resourceTools` to the Agent's
|
|
123
|
+
ordinary Tool catalog:
|
|
105
124
|
|
|
106
|
-
|
|
107
|
-
|
|
125
|
+
```ts
|
|
126
|
+
import { resourceTools } from "@constal/sdk";
|
|
108
127
|
|
|
109
|
-
|
|
128
|
+
export const tools = { ...resourceTools };
|
|
129
|
+
```
|
|
110
130
|
|
|
111
|
-
|
|
112
|
-
|
|
131
|
+
`resource_list` returns accepted binding names and CRNs without loading every
|
|
132
|
+
catalog. `resource_describe` takes `{ binding }` and returns that Resource's
|
|
133
|
+
public operations. `resource_invoke` accepts the described operation and its
|
|
134
|
+
arguments:
|
|
113
135
|
|
|
114
136
|
```ts
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
137
|
+
await resourceTools.resource_invoke.run({
|
|
138
|
+
binding: "tickets",
|
|
139
|
+
operation: "tool.find",
|
|
140
|
+
arguments: { query: "Open support requests" },
|
|
141
|
+
}, ctx);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
These Tools use the normal invocation, authorization, and asynchronous Handle
|
|
145
|
+
contracts. Results and errors are preserved. They do not install packages,
|
|
146
|
+
create Resources, change bindings, acquire credentials themselves, or retry
|
|
147
|
+
failed operations. Use the Constal API Resource for installation and rebind;
|
|
148
|
+
an accepted rebind receipt is not proof that the current frame has the new pin.
|
|
149
|
+
|
|
150
|
+
## Optional skills
|
|
151
|
+
|
|
152
|
+
Supply instructions directly or provide a source that loads them using your
|
|
153
|
+
existing Tools and Resources. The SDK does not search a filesystem or decide
|
|
154
|
+
which skill a task needs.
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { agent, skills } from "@constal/sdk";
|
|
158
|
+
|
|
159
|
+
const practices = skills([{
|
|
160
|
+
id: "testing",
|
|
161
|
+
description: "The team's testing conventions.",
|
|
162
|
+
instructions: "Use the existing package tests to establish and verify behavior.",
|
|
163
|
+
}]);
|
|
164
|
+
|
|
165
|
+
export default agent({
|
|
166
|
+
id: "maintainer", version: "1.0.0", model: "model",
|
|
167
|
+
tools: practices.tools,
|
|
168
|
+
async onMessage(request, ctx) {
|
|
169
|
+
return ctx.turn({
|
|
170
|
+
system: "You maintain the project's software.",
|
|
171
|
+
context: { request, skills: await practices.list(ctx) },
|
|
172
|
+
tools: Object.keys(practices.tools),
|
|
173
|
+
});
|
|
129
174
|
},
|
|
130
175
|
});
|
|
131
176
|
```
|
|
132
177
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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:
|
|
178
|
+
For a custom source, pass `list(ctx)` and `load(id, ctx)` functions instead of an
|
|
179
|
+
array. Declare its normal `needs` and `maxEffect` when loading uses Resources.
|
|
180
|
+
`list_skills` returns metadata; `read_skill` returns the complete instructions,
|
|
181
|
+
source when supplied, and content hash. These are ordinary authorized Tool calls.
|
|
182
|
+
Skill instructions do not grant additional authority.
|
|
183
|
+
|
|
184
|
+
## Model evaluation
|
|
185
|
+
|
|
186
|
+
`ctx.evaluate` judges one state against typed questions through an evaluation
|
|
187
|
+
Model such as `typesafe-ai/jev`. Every question is answered independently with
|
|
188
|
+
constrained values and probabilities, never generated prose, and the call is
|
|
189
|
+
journaled and priced like a model call without consuming a turn.
|
|
190
190
|
|
|
191
191
|
```ts
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
import { agent, noulDecision } from "@constal/sdk";
|
|
193
|
+
|
|
194
|
+
export default agent({
|
|
195
|
+
id: "triage", version: "1.0.0", model: "model",
|
|
196
|
+
async onMessage(ticket, ctx) {
|
|
197
|
+
const { answers } = await ctx.evaluate({
|
|
198
|
+
model: "judge",
|
|
199
|
+
state: { ticket },
|
|
200
|
+
questions: {
|
|
201
|
+
team: { type: "choice", instructions: "Which team owns `ticket`?",
|
|
202
|
+
criteria: { billing: "Charges, invoices, refunds", technical: { what: "Bugs and outages", not_for: "Charges" } } },
|
|
203
|
+
severity: { type: "score", instructions: "How severe is the problem in `ticket`?",
|
|
204
|
+
criteria: ["Cosmetic", "Degraded", "Customer is blocked"] },
|
|
205
|
+
urgent: { type: "noul", instructions: "Does `ticket` convey urgency?" },
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
if (answers.team.confidence < 0.5) return { route: "human" };
|
|
209
|
+
return { route: answers.team.choice, severity: answers.severity.score, urgent: noulDecision(answers.urgent, 0.7) };
|
|
210
|
+
},
|
|
211
|
+
});
|
|
196
212
|
```
|
|
197
213
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
214
|
+
Bind the evaluation Model like any other (`"judge": "crn:...:model/jev"`), or
|
|
215
|
+
pass `gateway` with an explicit `model` identifier. `instructions`, Choice option
|
|
216
|
+
descriptions, Score levels, and Noul criteria all accept JSON structure. Choice
|
|
217
|
+
answers keep the literal option keys of their criteria, Score answers carry a
|
|
218
|
+
`legend`, and Noul answers are a probability.
|
|
219
|
+
|
|
220
|
+
See [Evaluate state with a Model](https://constal.ai/docs/agents/evaluate) for a complete package manifest, answer shapes, and verification steps.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constal/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Public TypeScript SDK for authoring Constal agents, integrations, policies, channels, and credential providers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"constal",
|
|
@@ -33,10 +33,9 @@
|
|
|
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
|
|
36
|
+
"prepack": "npm run typecheck && npm test && npm run build"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@noble/hashes": "^2.0.1",
|
|
40
39
|
"esbuild": "^0.28.2",
|
|
41
40
|
"rollup": "^4.62.4",
|
|
42
41
|
"rollup-plugin-dts": "^6.2.3"
|