@constal/sdk 4.0.0 → 4.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constal/sdk",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
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.0.1",
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;
@@ -2391,6 +2395,8 @@ interface TurnDraft {
2391
2395
  final: boolean;
2392
2396
  artifact: unknown;
2393
2397
  completion?: ModelCompletion;
2398
+ refusal?: string;
2399
+ reasoningContent?: string;
2394
2400
  }
2395
2401
  interface TurnGate {
2396
2402
  id?: string;
@@ -2457,6 +2463,8 @@ interface TurnRecord {
2457
2463
  attempts: number;
2458
2464
  gate: GateVerdict | null;
2459
2465
  completion?: ModelCompletion;
2466
+ refusal?: string;
2467
+ reasoningContent?: string;
2460
2468
  }
2461
2469
  interface DataManifest {
2462
2470
  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) ?? {};