@constal/sdk 4.0.0 → 4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constal/sdk",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Public TypeScript SDK for authoring Constal agents, integrations, policies, channels, and credential providers",
5
5
  "keywords": [
6
6
  "constal",
package/publish/api.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "package": "@constal/sdk",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "exports": [
5
5
  "AGENT_UI_DEFAULTS",
6
6
  "Action",
@@ -673,6 +673,10 @@ interface ModelInvocationResult {
673
673
  name: string;
674
674
  args: unknown;
675
675
  }[];
676
+ /** Provider-reported refusal text, when present separately from visible content. */
677
+ refusal?: string;
678
+ /** Provider-exposed reasoning text or summary, when present. Output tokens alone do not imply either. */
679
+ reasoningContent?: string;
676
680
  /** Integration-observed timing for the complete upstream model request. */
677
681
  timing?: {
678
682
  upstreamMs: number;
@@ -1745,6 +1749,7 @@ interface SandboxMutationResult {
1745
1749
  interface SandboxImage {
1746
1750
  readonly id: string;
1747
1751
  readonly pool: SandboxPool;
1752
+ /** The cache key the image was created or resolved with; null when it has none, or when a handle from `SandboxPool.image` does not know it. */
1748
1753
  readonly cacheKey: string | null;
1749
1754
  delete(opts?: InvokeOpts): Promise<void>;
1750
1755
  }
@@ -1788,7 +1793,11 @@ interface SandboxPool {
1788
1793
  createImage(sandbox: Sandbox, options?: CreateSandboxImageOptions, opts?: InvokeOpts): Promise<SandboxImage>;
1789
1794
  /** Resolve an Agent-owned prepared image by its immutable environment digest. */
1790
1795
  resolveImage(cacheKey: string, opts?: InvokeOpts): Promise<SandboxImage | null>;
1791
- /** Register a logical Agent/Session sandbox; provider compute is allocated by its first work operation. */
1796
+ /** Address a pool-owned image recorded earlier, e.g. in a Fact. No invocation. The handle does not know the image's
1797
+ * cache key (`cacheKey` is null) and its delete() removes a setup-cache image too, so address only images the Agent recorded. */
1798
+ image(id: string): SandboxImage;
1799
+ /** Register a logical Agent/Session sandbox; provider compute is allocated by its first work operation. The pool refuses
1800
+ * an `image` while the Session's sandbox is live: delete that sandbox first to recreate it from an image. */
1792
1801
  createSandbox(agent: CRN, session: string, options?: CreateSandboxOptions, opts?: InvokeOpts): Promise<Sandbox>;
1793
1802
  }
1794
1803
 
@@ -2391,6 +2400,8 @@ interface TurnDraft {
2391
2400
  final: boolean;
2392
2401
  artifact: unknown;
2393
2402
  completion?: ModelCompletion;
2403
+ refusal?: string;
2404
+ reasoningContent?: string;
2394
2405
  }
2395
2406
  interface TurnGate {
2396
2407
  id?: string;
@@ -2457,6 +2468,8 @@ interface TurnRecord {
2457
2468
  attempts: number;
2458
2469
  gate: GateVerdict | null;
2459
2470
  completion?: ModelCompletion;
2471
+ refusal?: string;
2472
+ reasoningContent?: string;
2460
2473
  }
2461
2474
  interface DataManifest {
2462
2475
  hash: Hash;
package/publish/index.js CHANGED
@@ -3175,16 +3175,21 @@ function costMetadata(usage) {
3175
3175
  };
3176
3176
  }
3177
3177
  function modelProtocolResult(protocol, raw, provider, model) {
3178
- const source = record7(raw) ?? {};
3178
+ const source = record7(raw);
3179
+ if (!source) throw new TypeError("model gateway response is invalid");
3179
3180
  const toolCalls = [];
3180
3181
  let content2 = "";
3182
+ let refusal;
3183
+ let reasoningContent;
3181
3184
  let usage;
3182
3185
  if (protocol === "anthropic") {
3183
- const blocks = Array.isArray(source.content) ? source.content : [];
3186
+ if (!Array.isArray(source.content)) throw new TypeError("Anthropic model response content is invalid");
3187
+ const blocks = source.content;
3184
3188
  content2 = blocks.map((candidate) => {
3185
3189
  const block = record7(candidate);
3186
3190
  if (block?.type === "text" && typeof block.text === "string") return block.text;
3187
- if (block?.type === "tool_use" && typeof block.id === "string" && typeof block.name === "string") {
3191
+ if (block?.type === "tool_use") {
3192
+ if (typeof block.id !== "string" || typeof block.name !== "string") throw new TypeError("Anthropic tool use is invalid");
3188
3193
  toolCalls.push({ id: block.id, name: block.name, args: block.input ?? {} });
3189
3194
  }
3190
3195
  return "";
@@ -3198,13 +3203,19 @@ function modelProtocolResult(protocol, raw, provider, model) {
3198
3203
  ...costMetadata(values)
3199
3204
  };
3200
3205
  } else if (protocol === "openai") {
3201
- const choice = record7(Array.isArray(source.choices) ? source.choices[0] : null) ?? {};
3202
- const message2 = record7(choice.message) ?? {};
3206
+ const choice = record7(Array.isArray(source.choices) ? source.choices[0] : null);
3207
+ const message2 = record7(choice?.message);
3208
+ if (!message2) throw new TypeError("OpenAI-compatible model response message is invalid");
3203
3209
  content2 = typeof message2.content === "string" ? message2.content : "";
3210
+ refusal = typeof message2.refusal === "string" ? message2.refusal : void 0;
3211
+ reasoningContent = typeof message2.reasoning_content === "string" ? message2.reasoning_content : void 0;
3212
+ if (message2.tool_calls !== void 0 && !Array.isArray(message2.tool_calls)) throw new TypeError("OpenAI-compatible tool calls are invalid");
3204
3213
  for (const candidate of Array.isArray(message2.tool_calls) ? message2.tool_calls : []) {
3205
3214
  const call = record7(candidate);
3206
3215
  const fn = record7(call?.function);
3207
- if (typeof call?.id !== "string" || typeof fn?.name !== "string" || typeof fn.arguments !== "string") continue;
3216
+ if (typeof call?.id !== "string" || typeof fn?.name !== "string" || typeof fn.arguments !== "string") {
3217
+ throw new TypeError("OpenAI-compatible tool call is invalid");
3218
+ }
3208
3219
  let args;
3209
3220
  try {
3210
3221
  args = JSON.parse(fn.arguments);
@@ -3221,8 +3232,16 @@ function modelProtocolResult(protocol, raw, provider, model) {
3221
3232
  ...costMetadata(values)
3222
3233
  };
3223
3234
  } else throw new TypeError("model gateway protocol is invalid");
3224
- if (!content2 && toolCalls.length === 0) throw new TypeError("model gateway response had no content or Tool calls");
3225
- return { content: content2, ...toolCalls.length ? { toolCalls } : {}, usage, provider, model, completion: modelCompletionStatus(protocol, raw) };
3235
+ return {
3236
+ content: content2,
3237
+ ...toolCalls.length ? { toolCalls } : {},
3238
+ ...refusal === void 0 ? {} : { refusal },
3239
+ ...reasoningContent === void 0 ? {} : { reasoningContent },
3240
+ usage,
3241
+ provider,
3242
+ model,
3243
+ completion: modelCompletionStatus(protocol, raw)
3244
+ };
3226
3245
  }
3227
3246
  function modelCompletionStatus(protocol, raw) {
3228
3247
  const source = record7(raw) ?? {};