@namzu/sdk 64.1.0 → 64.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/provider/fallback.d.ts.map +1 -1
  3. package/dist/provider/fallback.js +2 -1
  4. package/dist/provider/fallback.js.map +1 -1
  5. package/dist/provider/idle-timeout.d.ts.map +1 -1
  6. package/dist/provider/idle-timeout.js +1 -1
  7. package/dist/provider/idle-timeout.js.map +1 -1
  8. package/dist/provider/retry.d.ts.map +1 -1
  9. package/dist/provider/retry.js +1 -1
  10. package/dist/provider/retry.js.map +1 -1
  11. package/dist/public-runtime.d.ts +1 -1
  12. package/dist/public-runtime.d.ts.map +1 -1
  13. package/dist/public-runtime.js +1 -1
  14. package/dist/public-runtime.js.map +1 -1
  15. package/dist/runtime/query/executor.d.ts +3 -1
  16. package/dist/runtime/query/executor.d.ts.map +1 -1
  17. package/dist/runtime/query/executor.js +1 -0
  18. package/dist/runtime/query/executor.js.map +1 -1
  19. package/dist/runtime/query/index.d.ts.map +1 -1
  20. package/dist/runtime/query/index.js +17 -0
  21. package/dist/runtime/query/index.js.map +1 -1
  22. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  23. package/dist/runtime/query/iteration/index.js +1 -1
  24. package/dist/runtime/query/iteration/index.js.map +1 -1
  25. package/dist/runtime/query/tooling.d.ts +3 -1
  26. package/dist/runtime/query/tooling.d.ts.map +1 -1
  27. package/dist/runtime/query/tooling.js +3 -0
  28. package/dist/runtime/query/tooling.js.map +1 -1
  29. package/dist/tools/builtins/skill.d.ts.map +1 -1
  30. package/dist/tools/builtins/skill.js +21 -1
  31. package/dist/tools/builtins/skill.js.map +1 -1
  32. package/dist/types/provider/interface.d.ts +5 -2
  33. package/dist/types/provider/interface.d.ts.map +1 -1
  34. package/dist/types/session/records.d.ts +73 -1
  35. package/dist/types/session/records.d.ts.map +1 -1
  36. package/dist/types/session/records.js +25 -0
  37. package/dist/types/session/records.js.map +1 -1
  38. package/dist/types/tool/index.d.ts +29 -0
  39. package/dist/types/tool/index.d.ts.map +1 -1
  40. package/dist/types/tool/index.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/provider/fallback.ts +7 -2
  43. package/src/provider/idle-timeout.ts +2 -1
  44. package/src/provider/retry.ts +2 -1
  45. package/src/public-runtime.ts +1 -0
  46. package/src/runtime/query/executor.ts +4 -0
  47. package/src/runtime/query/index.ts +16 -0
  48. package/src/runtime/query/iteration/index.ts +5 -1
  49. package/src/runtime/query/tooling.ts +11 -1
  50. package/src/tools/builtins/skill.ts +23 -1
  51. package/src/types/provider/interface.ts +9 -2
  52. package/src/types/session/records.ts +28 -0
  53. package/src/types/tool/index.ts +31 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@namzu/sdk",
3
- "version": "64.1.0",
3
+ "version": "64.3.0",
4
4
  "description": "Open-source AI kernel for TypeScript: runs an agent the way an operating system runs a process, with an identity and a budget, scheduled tool calls and checkpointed turns.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "engines": {
@@ -563,10 +563,15 @@ export function withProviderFallback(
563
563
  },
564
564
  // A chain takes a forced choice only if every member does: the request may
565
565
  // be served by any of them, and the one that refuses would fail the step.
566
- acceptsForcedToolChoiceFor: (model: string, thinking?: ThinkingConfig) =>
566
+ acceptsForcedToolChoiceFor: (
567
+ model: string,
568
+ thinking?: ThinkingConfig,
569
+ effort?: ReasoningEffort,
570
+ ) =>
567
571
  members.every(
568
572
  (member) =>
569
- member.provider.acceptsForcedToolChoiceFor?.(member.model ?? model, thinking) ?? true,
573
+ member.provider.acceptsForcedToolChoiceFor?.(member.model ?? model, thinking, effort) ??
574
+ true,
570
575
  ),
571
576
  reasoningEffortLevelsFor: (model: string, thinking?: ThinkingConfig) =>
572
577
  commonReasoningEffortLevels(members, model, thinking),
@@ -228,7 +228,8 @@ export function withStreamIdleTimeout(
228
228
  acceptsForcedToolChoiceFor: (
229
229
  model: string,
230
230
  thinking?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[1],
231
- ) => provider.acceptsForcedToolChoiceFor?.(model, thinking) ?? true,
231
+ effort?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[2],
232
+ ) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ?? true,
232
233
  }
233
234
  : {}),
234
235
  ...(provider.reasoningEffortLevelsFor
@@ -440,7 +440,8 @@ export function withProviderRetry(
440
440
  acceptsForcedToolChoiceFor: (
441
441
  model: string,
442
442
  thinking?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[1],
443
- ) => provider.acceptsForcedToolChoiceFor?.(model, thinking) ?? true,
443
+ effort?: Parameters<NonNullable<LLMProvider['acceptsForcedToolChoiceFor']>>[2],
444
+ ) => provider.acceptsForcedToolChoiceFor?.(model, thinking, effort) ?? true,
444
445
  }
445
446
  : {}),
446
447
  ...(provider.reasoningEffortLevelsFor
@@ -1923,6 +1923,7 @@ export {
1923
1923
  SessionLeaseDocumentSchema,
1924
1924
  SessionRecordSchema,
1925
1925
  SessionStartedRecordSchema,
1926
+ SkillHooksAttachedRecordSchema,
1926
1927
  TurnCompletedRecordSchema,
1927
1928
  TurnFailedRecordSchema,
1928
1929
  TurnOutcomeRecordedRecordSchema,
@@ -56,6 +56,7 @@ import type {
56
56
  PreparedToolExecution,
57
57
  RequestToolPause,
58
58
  ShellDialect,
59
+ SkillHooksRecordFact,
59
60
  SkillRegistryRef,
60
61
  ToolCallView,
61
62
  ToolContext,
@@ -556,6 +557,8 @@ export interface ToolExecutorConfig {
556
557
  authorizationGate?: AuthorizationGate
557
558
  /** Durable refusal sink paired with {@link authorizationGate}. */
558
559
  recordAudit?: (input: AuditEventInput) => Promise<unknown>
560
+ /** Where a skill's hooks are kept in the conversation's record; see `ToolContext.recordSkillHooks`. */
561
+ recordSkillHooks?: (fact: SkillHooksRecordFact) => Promise<boolean>
559
562
  /**
560
563
  * Where the `skill` tool's `allowed-tools` pre-approvals are recorded for
561
564
  * this turn. The review phase reads the same set. Absent: a loaded skill
@@ -2572,6 +2575,7 @@ export class ToolExecutor {
2572
2575
  ...(this.config.skillGrants
2573
2576
  ? { grantSkillTools: (grant) => this.grantSkillTools(grant) }
2574
2577
  : {}),
2578
+ ...(this.config.recordSkillHooks ? { recordSkillHooks: this.config.recordSkillHooks } : {}),
2575
2579
  maxToolOutputChars: this.config.maxToolOutputChars ?? DEFAULT_MAX_TOOL_OUTPUT_CHARS,
2576
2580
  // The turn's screens, defaulted HERE rather than on the registry: a
2577
2581
  // host builds the registry and hands it over, so a registry-side
@@ -1691,6 +1691,22 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
1691
1691
  ...(params.repairToolCall ? { repairToolCall: params.repairToolCall } : {}),
1692
1692
  ...(verificationGate ? { authorizationGate: verificationGate } : {}),
1693
1693
  recordAudit: (input) => ctx.recorder.recordAudit(input),
1694
+ recordSkillHooks: async (fact) => {
1695
+ try {
1696
+ await ctx.recorder.appendRecord({
1697
+ type: 'skill_hooks_attached',
1698
+ turnId: ctx.turnId,
1699
+ ignorable: true,
1700
+ skill: fact.skill,
1701
+ directory: fact.directory,
1702
+ grantsWithheld: fact.grantsWithheld,
1703
+ ...(fact.toolCallId !== undefined ? { toolCallId: fact.toolCallId } : {}),
1704
+ })
1705
+ return true
1706
+ } catch {
1707
+ return false
1708
+ }
1709
+ },
1694
1710
  // The durable pause, reachable from any tool rather than from the
1695
1711
  // four kernel-owned points that used to own it. Built here from
1696
1712
  // the machinery the turn already holds; the recorder binds a few
@@ -1234,7 +1234,11 @@ export class IterationOrchestrator {
1234
1234
  // its low effort and asks in words, on this request only.
1235
1235
  const forcedChoiceRefused =
1236
1236
  forcedAction &&
1237
- this.ctx.provider.acceptsForcedToolChoiceFor?.(stepModel, turnConfig.thinking) === false
1237
+ this.ctx.provider.acceptsForcedToolChoiceFor?.(
1238
+ stepModel,
1239
+ turnConfig.thinking,
1240
+ stepEffort,
1241
+ ) === false
1238
1242
  const operatorInputAtDispatch = this.latestUserMessage
1239
1243
  const latestReviewUserMessage =
1240
1244
  (this.ctx.reviewAnswer || this.ctx.structuredOutput?.review) && operatorInputAtDispatch
@@ -8,7 +8,12 @@ import type { InvocationState } from '../../types/invocation/index.js'
8
8
  import type { PermissionMode } from '../../types/permission/index.js'
9
9
  import type { AuditEventInput } from '../../types/session/audit.js'
10
10
  import type { SessionRecord } from '../../types/session/records.js'
11
- import type { RequestToolPause, SkillRegistryRef, ToolDefinition } from '../../types/tool/index.js'
11
+ import type {
12
+ RequestToolPause,
13
+ SkillHooksRecordFact,
14
+ SkillRegistryRef,
15
+ ToolDefinition,
16
+ } from '../../types/tool/index.js'
12
17
  import type { RepairToolCall } from '../../types/tool/repair.js'
13
18
  import type { BackoffPolicy } from '../../utils/backoff.js'
14
19
  import type { Logger } from '../../utils/logger.js'
@@ -81,6 +86,8 @@ export interface ToolingBootstrapConfig {
81
86
  authorizationGate?: AuthorizationGate
82
87
  /** Durable refusal recorder for nested authorization decisions. */
83
88
  recordAudit?: (input: AuditEventInput) => Promise<unknown>
89
+ /** Where a skill's hooks are kept in the conversation's record. */
90
+ recordSkillHooks?: (fact: SkillHooksRecordFact) => Promise<boolean>
84
91
  /** Builds the durable-pause seam for one tool call; see ToolContext.requestPause. */
85
92
  toolPause?: (toolUseId: string) => RequestToolPause
86
93
  /** The turn's skill pre-approvals; see the executor's own field. */
@@ -166,6 +173,9 @@ export class ToolingBootstrap {
166
173
  ? { authorizationGate: config.authorizationGate }
167
174
  : {}),
168
175
  ...(config.recordAudit !== undefined ? { recordAudit: config.recordAudit } : {}),
176
+ ...(config.recordSkillHooks !== undefined
177
+ ? { recordSkillHooks: config.recordSkillHooks }
178
+ : {}),
169
179
  ...(config.toolPause !== undefined ? { toolPause: config.toolPause } : {}),
170
180
  ...(config.skillGrants !== undefined ? { skillGrants: config.skillGrants } : {}),
171
181
  },
@@ -613,10 +613,28 @@ export function createSkillTool(options: SkillToolOptions = {}) {
613
613
  grant?.commit()
614
614
  // Live only now that the instructions were delivered, like the grant.
615
615
  hooksPlan?.attach()
616
+ // Kept with the conversation, so a host that continues it later can
617
+ // attach the same hooks again. Once, on the first page of a load.
618
+ let output = page.output
619
+ if (hooksPlan?.resumable === true && start === 0 && skill.dirPath !== undefined) {
620
+ const kept = context.recordSkillHooks
621
+ ? await context
622
+ .recordSkillHooks({
623
+ skill: skill.metadata.name,
624
+ directory: skill.dirPath,
625
+ grantsWithheld: hooksPlan.withholdGrants,
626
+ ...(context.toolUseId !== undefined ? { toolCallId: context.toolUseId } : {}),
627
+ })
628
+ .catch(() => false)
629
+ : false
630
+ if (!kept) {
631
+ output += `\n\n[${SKILL_HOOKS_NOT_KEPT}]`
632
+ }
633
+ }
616
634
 
617
635
  return {
618
636
  success: true,
619
- output: page.output,
637
+ output,
620
638
  data: {
621
639
  skill: skill.metadata.name,
622
640
  ...(modelDirectory === undefined ? {} : { directory: modelDirectory }),
@@ -629,6 +647,10 @@ export function createSkillTool(options: SkillToolOptions = {}) {
629
647
  })
630
648
  }
631
649
 
650
+ /** Said to the model when a skill's hooks could not be written into the conversation's record. */
651
+ const SKILL_HOOKS_NOT_KEPT =
652
+ "This conversation could not keep a record of this skill's hooks, so if it is continued later they will not be attached again: load the skill again then."
653
+
632
654
  /**
633
655
  * What the host says of the hooks a skill carries, or `undefined` for a skill
634
656
  * that carries none. A registry that cannot read hooks answers with a plan
@@ -185,12 +185,19 @@ export interface LLMProvider {
185
185
  *
186
186
  * The kernel asks before it requires a tool call on a step it wants to act,
187
187
  * and when the answer is `false` it keeps the step at low effort and asks the
188
- * model in words instead of sending a choice the driver would refuse. Optional:
188
+ * model in words instead of sending a choice the driver would refuse. `effort`
189
+ * is the level the request will carry, for a driver where the level also
190
+ * decides whether thinking is on (a provider that does not need it ignores
191
+ * it). Optional:
189
192
  * a provider that does not declare it is treated as taking the choice, so
190
193
  * every existing driver behaves as before. A wrapper that rebuilds a provider
191
194
  * forwards it.
192
195
  */
193
- acceptsForcedToolChoiceFor?(model: string, thinking?: import('./chat.js').ThinkingConfig): boolean
196
+ acceptsForcedToolChoiceFor?(
197
+ model: string,
198
+ thinking?: import('./chat.js').ThinkingConfig,
199
+ effort?: import('./chat.js').ReasoningEffort,
200
+ ): boolean
194
201
 
195
202
  /**
196
203
  * The effort a model uses when a request omits an explicit level.
@@ -660,6 +660,31 @@ export const OutcomeProgressWrittenRecordSchema = inTurn('outcome_progress_writt
660
660
  progress: outcomeBody,
661
661
  })
662
662
 
663
+ /**
664
+ * A skill's hooks were attached to the conversation (or refused) when the model
665
+ * loaded it. Written by the `skill` tool's host in the turn that loaded it,
666
+ * flagged `ignorable`: a release that does not know the type skips it, keeps it
667
+ * in the hash chain and folds the conversation as before, and a host that does
668
+ * know it attaches the skill's hooks again when the conversation is continued
669
+ * (`docs/sdk/hooks.md`, "Hooks in a skill"). Never a field of a record that
670
+ * existed before it, for the reason the outcome records give above.
671
+ *
672
+ * Carries the turn's id when the skill was loaded in a turn, and none when a
673
+ * copy of a conversation (a fork) carries the record over.
674
+ *
675
+ * `directory` is the skill's own folder, `grantsWithheld` whether its
676
+ * `allowed-tools` were left unapproved, and `toolCallId` the `skill` call that
677
+ * loaded it, so a copy of a conversation that stops before that call can leave
678
+ * the record behind.
679
+ */
680
+ export const SkillHooksAttachedRecordSchema = recordSchema('skill_hooks_attached', {
681
+ ignorable: z.literal(true),
682
+ skill: text.min(1),
683
+ directory: text.min(1),
684
+ grantsWithheld: z.boolean(),
685
+ toolCallId: text.min(1).optional(),
686
+ })
687
+
663
688
  export const LogRepairedRecordSchema = recordSchema('log_repaired', {
664
689
  truncatedBytes: positive,
665
690
  lastGoodSeq: positive,
@@ -702,6 +727,7 @@ const RECORD_ONLY_SCHEMAS = {
702
727
  turn_outcome_recorded: TurnOutcomeRecordedRecordSchema,
703
728
  child_outcome_recorded: ChildOutcomeRecordedRecordSchema,
704
729
  outcome_progress_written: OutcomeProgressWrittenRecordSchema,
730
+ skill_hooks_attached: SkillHooksAttachedRecordSchema,
705
731
  } as const
706
732
 
707
733
  export type SessionRecordOnlyType = keyof typeof RECORD_ONLY_SCHEMAS
@@ -1124,6 +1150,7 @@ export type LogRepairedRecord = z.infer<typeof LogRepairedRecordSchema>
1124
1150
  export type TurnOutcomeRecordedRecord = z.infer<typeof TurnOutcomeRecordedRecordSchema>
1125
1151
  export type ChildOutcomeRecordedRecord = z.infer<typeof ChildOutcomeRecordedRecordSchema>
1126
1152
  export type OutcomeProgressWrittenRecord = z.infer<typeof OutcomeProgressWrittenRecordSchema>
1153
+ export type SkillHooksAttachedRecord = z.infer<typeof SkillHooksAttachedRecordSchema>
1127
1154
 
1128
1155
  export type SessionRecordOnly =
1129
1156
  | SessionStartedRecord
@@ -1145,6 +1172,7 @@ export type SessionRecordOnly =
1145
1172
  | TurnOutcomeRecordedRecord
1146
1173
  | ChildOutcomeRecordedRecord
1147
1174
  | OutcomeProgressWrittenRecord
1175
+ | SkillHooksAttachedRecord
1148
1176
 
1149
1177
  /** One line of a session log. */
1150
1178
  export type SessionRecord = SessionEventRecord | SessionRecordOnly
@@ -136,6 +136,18 @@ export interface SkillRegistryRef {
136
136
  ): SkillHooksPlan
137
137
  }
138
138
 
139
+ /** What a conversation keeps of a skill whose hooks were attached to it; see {@link ToolContext.recordSkillHooks}. */
140
+ export interface SkillHooksRecordFact {
141
+ /** The skill's name. */
142
+ readonly skill: string
143
+ /** The skill's own folder. */
144
+ readonly directory: string
145
+ /** The skill's `allowed-tools` were left unapproved (a hook that guards its work could not be loaded). */
146
+ readonly grantsWithheld: boolean
147
+ /** The `skill` call that loaded it. */
148
+ readonly toolCallId?: string
149
+ }
150
+
139
151
  /** What the `skill` tool tells a host's hook reader about the use it is making of a skill. */
140
152
  export interface SkillHooksOptions {
141
153
  /** The skill runs in a delegated agent: its hooks belong to that agent's run only. */
@@ -158,6 +170,14 @@ export interface SkillHooksPlan {
158
170
  * guards its work could not be loaded, or hooks cannot be attached here.
159
171
  */
160
172
  readonly withholdGrants: boolean
173
+ /**
174
+ * The hooks (or the refusal) belong to the conversation and should come
175
+ * back when it is continued: the `skill` tool keeps a record of the use
176
+ * ({@link ToolContext.recordSkillHooks}) once the instructions were
177
+ * delivered. Absent or false: nothing is kept (a forked skill, whose hooks
178
+ * belong to one run; a skill whose hooks are switched off).
179
+ */
180
+ readonly resumable?: boolean
161
181
  /** Make the hooks live. Idempotent for a skill already attached to the conversation. */
162
182
  attach(): SkillHooksHandle
163
183
  }
@@ -865,6 +885,17 @@ export interface ToolContext {
865
885
  readonly commit: () => void
866
886
  }
867
887
 
888
+ /**
889
+ * Keep, in the conversation's own record, that a skill's hooks were attached
890
+ * (or refused) for it, so a host that continues the conversation later can
891
+ * attach them again. Called by the `skill` tool once the instructions were
892
+ * delivered, only for a skill the host's {@link SkillHooksPlan.resumable}
893
+ * names. Resolves `true` when the record was written; `false` (it does not
894
+ * throw) when it could not be, and the tool then says so in its result.
895
+ * Absent outside a turn that has a session log.
896
+ */
897
+ recordSkillHooks?: (fact: SkillHooksRecordFact) => Promise<boolean>
898
+
868
899
  /**
869
900
  * Effective model-visible character cap for this tool result.
870
901
  *