@roll-agent/runtime 0.26.0 → 1.0.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 (89) hide show
  1. package/dist/engine/agent-session.d.ts +14 -5
  2. package/dist/engine/agent-session.js +1 -1
  3. package/dist/engine/cancelled-turn-recovery.d.ts +1 -11
  4. package/dist/engine/capability-manifest.d.ts +3 -3
  5. package/dist/engine/compaction-checkpoint.d.ts +486 -3903
  6. package/dist/engine/compaction-checkpoint.js +1 -1
  7. package/dist/engine/compaction-semantic-state.d.ts +210 -1804
  8. package/dist/engine/conversation-engine.d.ts +26 -42
  9. package/dist/engine/conversation-engine.js +1 -1
  10. package/dist/engine/explicit-skill-context.d.ts +6 -62
  11. package/dist/engine/explicit-skill-context.js +1 -1
  12. package/dist/engine/model-catalog.d.ts +3 -27
  13. package/dist/engine/model-recovery.d.ts +21 -0
  14. package/dist/engine/model-recovery.js +1 -0
  15. package/dist/engine/request-budget.d.ts +9 -50
  16. package/dist/host-contracts/agent-host.d.ts +39 -0
  17. package/dist/host-contracts/agent-host.js +1 -0
  18. package/dist/host-contracts/index.d.ts +7 -0
  19. package/dist/host-contracts/index.js +1 -0
  20. package/dist/host-contracts/runtime-settings.d.ts +68 -0
  21. package/dist/host-contracts/runtime-settings.js +1 -0
  22. package/dist/host-contracts/schedule-tools.d.ts +138 -0
  23. package/dist/host-contracts/schedule-tools.js +1 -0
  24. package/dist/index.d.ts +7 -1
  25. package/dist/index.js +1 -1
  26. package/dist/interaction/user-input-interaction-manager.d.ts +1 -1
  27. package/dist/scheduler/calendar.d.ts +13 -51
  28. package/dist/scheduler/trigger.d.ts +20 -156
  29. package/dist/server/protocol.d.ts +11 -73
  30. package/dist/server/runtime-client-interaction-lifecycle.d.ts +2 -2
  31. package/dist/skills/contracts.d.ts +24 -0
  32. package/dist/skills/contracts.js +1 -0
  33. package/dist/skills/index.d.ts +2 -0
  34. package/dist/skills/index.js +1 -0
  35. package/dist/skills/invocation.d.ts +29 -0
  36. package/dist/skills/invocation.js +1 -0
  37. package/dist/store/semantic-ledger.d.ts +27 -72
  38. package/dist/store/thread-origin.d.ts +8 -100
  39. package/dist/store/thread-store.d.ts +3 -3
  40. package/dist/store/turn-input.d.ts +11 -135
  41. package/dist/store/turn-input.js +1 -1
  42. package/dist/tool-bridge/bash-tool.d.ts +1 -13
  43. package/dist/tool-bridge/build-tools.d.ts +5 -5
  44. package/dist/tool-bridge/build-tools.js +1 -1
  45. package/dist/tool-bridge/file-tools/edit-file-tool.d.ts +2 -24
  46. package/dist/tool-bridge/file-tools/glob-tool.d.ts +1 -7
  47. package/dist/tool-bridge/file-tools/grep-tool.d.ts +1 -15
  48. package/dist/tool-bridge/file-tools/list-dir-tool.d.ts +1 -5
  49. package/dist/tool-bridge/file-tools/read-file-tool.d.ts +1 -9
  50. package/dist/tool-bridge/file-tools/verify-file-tool.d.ts +5 -8
  51. package/dist/tool-bridge/file-tools/write-file-tool.d.ts +1 -7
  52. package/dist/tool-bridge/model-input-schema.d.ts +3 -0
  53. package/dist/tool-bridge/model-input-schema.js +1 -0
  54. package/dist/tool-bridge/naming.d.ts +2 -2
  55. package/dist/tool-bridge/normalize-result.js +1 -1
  56. package/dist/tool-bridge/observation-recall-tool.d.ts +1 -9
  57. package/dist/tool-bridge/schedule-create-input.d.ts +9 -75
  58. package/dist/tool-bridge/schedule-tool.d.ts +1 -1
  59. package/dist/tool-bridge/schedule-tool.js +1 -1
  60. package/dist/tool-bridge/session-exec-tool.d.ts +3 -23
  61. package/dist/tool-bridge/skill-tool.d.ts +2 -8
  62. package/dist/tool-bridge/skill-tool.js +1 -1
  63. package/dist/tool-bridge/tool-approval-continuation.d.ts +1 -1
  64. package/dist/tool-bridge/tool-approval-continuation.js +1 -1
  65. package/dist/tool-bridge/tool-execution-coordinator.d.ts +3 -26
  66. package/dist/tool-bridge/tool-execution-coordinator.js +1 -1
  67. package/dist/tool-bridge/transcript-tool.d.ts +7 -35
  68. package/dist/tool-bridge/user-input-tool.js +1 -1
  69. package/dist/tool-contracts/agent-types.d.ts +32 -0
  70. package/dist/tool-contracts/agent-types.js +1 -0
  71. package/dist/tool-contracts/execution-timeout.d.ts +2 -0
  72. package/dist/tool-contracts/execution-timeout.js +1 -0
  73. package/dist/tool-contracts/index.d.ts +8 -0
  74. package/dist/tool-contracts/index.js +1 -0
  75. package/dist/tool-contracts/issues.d.ts +22 -0
  76. package/dist/tool-contracts/issues.js +1 -0
  77. package/dist/tool-contracts/json-schema-refs.d.ts +19 -0
  78. package/dist/tool-contracts/json-schema-refs.js +1 -0
  79. package/dist/tool-contracts/preflight.d.ts +16 -0
  80. package/dist/tool-contracts/preflight.js +1 -0
  81. package/dist/tool-contracts/resource-hints.d.ts +26 -0
  82. package/dist/tool-contracts/resource-hints.js +1 -0
  83. package/dist/tool-contracts/results.d.ts +7 -0
  84. package/dist/tool-contracts/results.js +1 -0
  85. package/dist/tool-contracts/schema.d.ts +13 -0
  86. package/dist/tool-contracts/schema.js +1 -0
  87. package/dist/types/cancellation.d.ts +6 -10
  88. package/dist/types/events.d.ts +7 -0
  89. package/package.json +18 -7
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod/v4";
2
2
  import type { ApprovalId, InteractionId, JsonRpcId, RuntimeInstanceId, RuntimeProtocolVersion, RuntimeServerRequestMethod } from "@roll-agent/protocol";
3
- declare const logicalInteractionKeySchema: z.core.$ZodBranded<z.ZodString, "LogicalInteractionKey">;
4
- declare const runtimeDeliveryIdSchema: z.core.$ZodBranded<z.ZodString, "RuntimeDeliveryId">;
3
+ declare const logicalInteractionKeySchema: z.core.$ZodBranded<z.ZodString, "LogicalInteractionKey", "out">;
4
+ declare const runtimeDeliveryIdSchema: z.core.$ZodBranded<z.ZodString, "RuntimeDeliveryId", "out">;
5
5
  export type LogicalInteractionKey = z.output<typeof logicalInteractionKeySchema>;
6
6
  export type RuntimeDeliveryId = z.output<typeof runtimeDeliveryIdSchema>;
7
7
  export interface RuntimeClientInteractionInput<TResponderId extends string> {
@@ -0,0 +1,24 @@
1
+ export declare const SKILL_SOURCES: readonly ["agent", "project", "user", "config"];
2
+ export type SkillSource = (typeof SKILL_SOURCES)[number];
3
+ export interface SkillSummary {
4
+ readonly name: string;
5
+ readonly description: string;
6
+ readonly source: SkillSource;
7
+ }
8
+ export interface LoadedSkill {
9
+ readonly summary: SkillSummary;
10
+ readonly content: string;
11
+ readonly referencePaths: readonly string[];
12
+ readonly skillRoot?: string;
13
+ }
14
+ export interface LoadedSkillReference {
15
+ readonly content: string;
16
+ readonly skillRoot?: string;
17
+ }
18
+ export interface SkillLibrary {
19
+ list(): readonly SkillSummary[];
20
+ load(name: string): LoadedSkill | undefined;
21
+ loadReference(name: string, referencePath: string): string | undefined;
22
+ loadReferenceDocument?(name: string, referencePath: string): LoadedSkillReference | undefined;
23
+ }
24
+ export declare const SKILL_TOOL_ID = "roll__skill";
@@ -0,0 +1 @@
1
+ export const SKILL_SOURCES=["agent","project","user","config"];export const SKILL_TOOL_ID="roll__skill";
@@ -0,0 +1,2 @@
1
+ export * from "./contracts.ts";
2
+ export * from "./invocation.ts";
@@ -0,0 +1 @@
1
+ export*from"./contracts.js";export*from"./invocation.js";
@@ -0,0 +1,29 @@
1
+ export interface SkillInvocationSummary {
2
+ readonly name: string;
3
+ readonly description: string;
4
+ readonly source: string;
5
+ }
6
+ export interface SkillInvocation {
7
+ readonly skills: readonly SkillInvocationSummary[];
8
+ readonly prompt: string;
9
+ }
10
+ export declare const SKILL_INVOCATION_PARSE_KINDS: {
11
+ readonly none: "none";
12
+ readonly valid: "valid";
13
+ readonly unknown: "unknown";
14
+ };
15
+ export type SkillInvocationParseResult = {
16
+ readonly kind: typeof SKILL_INVOCATION_PARSE_KINDS.none;
17
+ } | {
18
+ readonly kind: typeof SKILL_INVOCATION_PARSE_KINDS.valid;
19
+ readonly invocation: SkillInvocation;
20
+ } | {
21
+ readonly kind: typeof SKILL_INVOCATION_PARSE_KINDS.unknown;
22
+ readonly token: string;
23
+ };
24
+ export declare function isSlashCommandToken(token: string): boolean;
25
+ export declare function isSlashCommandShaped(input: string): boolean;
26
+ export declare function findSkillBySlashName(token: string, skills: readonly SkillInvocationSummary[]): SkillInvocationSummary | undefined;
27
+ /** Parses one or more known leading /skill tokens without rewriting the user's request. */
28
+ export declare function parseSkillInvocationResult(input: string, skills: readonly SkillInvocationSummary[]): SkillInvocationParseResult;
29
+ export declare function parseSkillInvocation(input: string, skills: readonly SkillInvocationSummary[]): SkillInvocation | undefined;
@@ -0,0 +1 @@
1
+ export const SKILL_INVOCATION_PARSE_KINDS={none:"none",valid:"valid",unknown:"unknown"};const n=/^\/[\w-]*$/;export function isSlashCommandToken(o){return n.test(o)}export function isSlashCommandShaped(n){return isSlashCommandToken(n.split(/\s+/,1)[0]??"")}export function findSkillBySlashName(n,o){const t=n.toLowerCase();return o.find(n=>`/${n.name}`.toLowerCase()===t)}export function parseSkillInvocationResult(n,o){let t=n.trimStart();const e=[],i=new Set;for(;;){const n=/^(\/\S+)(\s*)/.exec(t);if(!n)break;const s=n[1]??"";if(!isSlashCommandToken(s))break;const a=findSkillBySlashName(s,o);if(!a)return{kind:SKILL_INVOCATION_PARSE_KINDS.unknown,token:s};const r=a.name.toLowerCase();i.has(r)||(e.push(a),i.add(r)),t=t.slice(n[0].length)}return 0===e.length?{kind:SKILL_INVOCATION_PARSE_KINDS.none}:{kind:SKILL_INVOCATION_PARSE_KINDS.valid,invocation:{skills:e,prompt:t.trim()}}}export function parseSkillInvocation(n,o){const t=parseSkillInvocationResult(n,o);return t.kind===SKILL_INVOCATION_PARSE_KINDS.valid?t.invocation:void 0}
@@ -5,16 +5,11 @@ export declare const SEMANTIC_LEDGER_SQL = "\nCREATE TABLE IF NOT EXISTS compact
5
5
  export declare const contextRecoveryItemSchema: z.ZodObject<{
6
6
  itemId: z.ZodString;
7
7
  version: z.ZodNumber;
8
- category: z.ZodEnum<["goal", "constraint"]>;
9
- }, "strip", z.ZodTypeAny, {
10
- version: number;
11
- itemId: string;
12
- category: "goal" | "constraint";
13
- }, {
14
- version: number;
15
- itemId: string;
16
- category: "goal" | "constraint";
17
- }>;
8
+ category: z.ZodEnum<{
9
+ goal: "goal";
10
+ constraint: "constraint";
11
+ }>;
12
+ }, z.core.$strip>;
18
13
  export declare const recoveryStateSchema: z.ZodObject<{
19
14
  checkpointId: z.ZodString;
20
15
  required: z.ZodBoolean;
@@ -23,77 +18,37 @@ export declare const recoveryStateSchema: z.ZodObject<{
23
18
  requiredItems: z.ZodDefault<z.ZodArray<z.ZodObject<{
24
19
  itemId: z.ZodString;
25
20
  version: z.ZodNumber;
26
- category: z.ZodEnum<["goal", "constraint"]>;
27
- }, "strip", z.ZodTypeAny, {
28
- version: number;
29
- itemId: string;
30
- category: "goal" | "constraint";
31
- }, {
32
- version: number;
33
- itemId: string;
34
- category: "goal" | "constraint";
35
- }>, "many">>;
36
- }, "strip", z.ZodTypeAny, {
37
- required: boolean;
38
- checkpointId: string;
39
- unextracted: boolean;
40
- memo: string;
41
- requiredItems: {
42
- version: number;
43
- itemId: string;
44
- category: "goal" | "constraint";
45
- }[];
46
- }, {
47
- required: boolean;
48
- checkpointId: string;
49
- unextracted: boolean;
50
- memo: string;
51
- requiredItems?: {
52
- version: number;
53
- itemId: string;
54
- category: "goal" | "constraint";
55
- }[] | undefined;
56
- }>;
21
+ category: z.ZodEnum<{
22
+ goal: "goal";
23
+ constraint: "constraint";
24
+ }>;
25
+ }, z.core.$strip>>>;
26
+ }, z.core.$strip>;
57
27
  export type ContextRecoveryState = z.infer<typeof recoveryStateSchema>;
58
28
  export declare const contextRecoveryNoteSchema: z.ZodObject<{
59
29
  checkpointId: z.ZodString;
60
30
  notes: z.ZodString;
61
- }, "strip", z.ZodTypeAny, {
62
- checkpointId: string;
63
- notes: string;
64
- }, {
65
- checkpointId: string;
66
- notes: string;
67
- }>;
31
+ }, z.core.$strip>;
68
32
  export type ContextRecoveryNote = z.infer<typeof contextRecoveryNoteSchema>;
69
33
  export declare const ledgerRowSchema: z.ZodObject<{
70
34
  item_id: z.ZodString;
71
35
  generation: z.ZodNumber;
72
36
  scope: z.ZodString;
73
- category: z.ZodEnum<["goal", "constraint", "decision", "completed_work", "pending_work", "resource", "running_session", "uncertainty"]>;
37
+ category: z.ZodEnum<{
38
+ decision: "decision";
39
+ resource: "resource";
40
+ running_session: "running_session";
41
+ goal: "goal";
42
+ constraint: "constraint";
43
+ completed_work: "completed_work";
44
+ pending_work: "pending_work";
45
+ uncertainty: "uncertainty";
46
+ }>;
74
47
  status: z.ZodString;
75
48
  resolution_json: z.ZodOptional<z.ZodNullable<z.ZodString>>;
76
49
  first_tool_sequence: z.ZodNumber;
77
50
  item_json: z.ZodString;
78
- }, "strip", z.ZodTypeAny, {
79
- status: string;
80
- generation: number;
81
- scope: string;
82
- category: "resource" | "decision" | "running_session" | "goal" | "constraint" | "completed_work" | "pending_work" | "uncertainty";
83
- item_id: string;
84
- first_tool_sequence: number;
85
- item_json: string;
86
- resolution_json?: string | null | undefined;
87
- }, {
88
- status: string;
89
- generation: number;
90
- scope: string;
91
- category: "resource" | "decision" | "running_session" | "goal" | "constraint" | "completed_work" | "pending_work" | "uncertainty";
92
- item_id: string;
93
- first_tool_sequence: number;
94
- item_json: string;
95
- resolution_json?: string | null | undefined;
96
- }>;
51
+ }, z.core.$strip>;
97
52
  export type SemanticLedgerRow = z.infer<typeof ledgerRowSchema>;
98
53
  /** Compatibility reader/importer for historical V2 records. New checkpoints never append here. */
99
54
  export declare class SemanticLedger {
@@ -102,14 +57,14 @@ export declare class SemanticLedger {
102
57
  rows(threadId: string, generation: number, itemId?: string): SemanticLedgerRow[];
103
58
  /** Stable ordinals within an immutable checkpoint generation; fetch only the requested page. */
104
59
  page(threadId: string, generation: number, afterSequence: number, limit: number): {
105
- status: string;
60
+ item_id: string;
106
61
  generation: number;
107
62
  scope: string;
108
- sequence: number;
109
- category: "resource" | "decision" | "running_session" | "goal" | "constraint" | "completed_work" | "pending_work" | "uncertainty";
110
- item_id: string;
63
+ category: "decision" | "resource" | "running_session" | "goal" | "constraint" | "completed_work" | "pending_work" | "uncertainty";
64
+ status: string;
111
65
  first_tool_sequence: number;
112
66
  item_json: string;
67
+ sequence: number;
113
68
  resolution_json?: string | null | undefined;
114
69
  }[];
115
70
  notes(threadId: string): ContextRecoveryNote[];
@@ -9,32 +9,10 @@ export declare const scheduledThreadOriginSchema: z.ZodReadonly<z.ZodObject<{
9
9
  cwd: z.ZodString;
10
10
  scheduledFor: z.ZodString;
11
11
  ledgerDir: z.ZodString;
12
- }, "strict", z.ZodTypeAny, {
13
- kind: "scheduled";
14
- name: string;
15
- cwd: string;
16
- attempt: number;
17
- scheduleId: string;
18
- invocationId: string;
19
- scheduledFor: string;
20
- ledgerDir: string;
21
- }, {
22
- kind: "scheduled";
23
- name: string;
24
- cwd: string;
25
- attempt: number;
26
- scheduleId: string;
27
- invocationId: string;
28
- scheduledFor: string;
29
- ledgerDir: string;
30
- }>>;
31
- export declare const threadOriginSchema: z.ZodReadonly<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
12
+ }, z.core.$strict>>;
13
+ export declare const threadOriginSchema: z.ZodReadonly<z.ZodDiscriminatedUnion<[z.ZodObject<{
32
14
  kind: z.ZodLiteral<"interactive">;
33
- }, "strict", z.ZodTypeAny, {
34
- kind: "interactive";
35
- }, {
36
- kind: "interactive";
37
- }>, z.ZodObject<{
15
+ }, z.core.$strict>, z.ZodObject<{
38
16
  kind: z.ZodLiteral<"scheduled">;
39
17
  scheduleId: z.ZodString;
40
18
  invocationId: z.ZodString;
@@ -43,34 +21,12 @@ export declare const threadOriginSchema: z.ZodReadonly<z.ZodDiscriminatedUnion<"
43
21
  cwd: z.ZodString;
44
22
  scheduledFor: z.ZodString;
45
23
  ledgerDir: z.ZodString;
46
- }, "strict", z.ZodTypeAny, {
47
- kind: "scheduled";
48
- name: string;
49
- cwd: string;
50
- attempt: number;
51
- scheduleId: string;
52
- invocationId: string;
53
- scheduledFor: string;
54
- ledgerDir: string;
55
- }, {
56
- kind: "scheduled";
57
- name: string;
58
- cwd: string;
59
- attempt: number;
60
- scheduleId: string;
61
- invocationId: string;
62
- scheduledFor: string;
63
- ledgerDir: string;
64
- }>]>>;
24
+ }, z.core.$strict>], "kind">>;
65
25
  export declare const threadDerivedFromSchema: z.ZodReadonly<z.ZodObject<{
66
26
  threadId: z.ZodString;
67
- origin: z.ZodReadonly<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
27
+ origin: z.ZodReadonly<z.ZodDiscriminatedUnion<[z.ZodObject<{
68
28
  kind: z.ZodLiteral<"interactive">;
69
- }, "strict", z.ZodTypeAny, {
70
- kind: "interactive";
71
- }, {
72
- kind: "interactive";
73
- }>, z.ZodObject<{
29
+ }, z.core.$strict>, z.ZodObject<{
74
30
  kind: z.ZodLiteral<"scheduled">;
75
31
  scheduleId: z.ZodString;
76
32
  invocationId: z.ZodString;
@@ -79,57 +35,9 @@ export declare const threadDerivedFromSchema: z.ZodReadonly<z.ZodObject<{
79
35
  cwd: z.ZodString;
80
36
  scheduledFor: z.ZodString;
81
37
  ledgerDir: z.ZodString;
82
- }, "strict", z.ZodTypeAny, {
83
- kind: "scheduled";
84
- name: string;
85
- cwd: string;
86
- attempt: number;
87
- scheduleId: string;
88
- invocationId: string;
89
- scheduledFor: string;
90
- ledgerDir: string;
91
- }, {
92
- kind: "scheduled";
93
- name: string;
94
- cwd: string;
95
- attempt: number;
96
- scheduleId: string;
97
- invocationId: string;
98
- scheduledFor: string;
99
- ledgerDir: string;
100
- }>]>>;
38
+ }, z.core.$strict>], "kind">>;
101
39
  capturedAt: z.ZodString;
102
- }, "strict", z.ZodTypeAny, {
103
- threadId: string;
104
- origin: Readonly<{
105
- kind: "scheduled";
106
- name: string;
107
- cwd: string;
108
- attempt: number;
109
- scheduleId: string;
110
- invocationId: string;
111
- scheduledFor: string;
112
- ledgerDir: string;
113
- }> | Readonly<{
114
- kind: "interactive";
115
- }>;
116
- capturedAt: string;
117
- }, {
118
- threadId: string;
119
- origin: Readonly<{
120
- kind: "scheduled";
121
- name: string;
122
- cwd: string;
123
- attempt: number;
124
- scheduleId: string;
125
- invocationId: string;
126
- scheduledFor: string;
127
- ledgerDir: string;
128
- }> | Readonly<{
129
- kind: "interactive";
130
- }>;
131
- capturedAt: string;
132
- }>>;
40
+ }, z.core.$strict>>;
133
41
  export type ThreadOrigin = z.infer<typeof threadOriginSchema>;
134
42
  export type ScheduledThreadOrigin = z.infer<typeof scheduledThreadOriginSchema>;
135
43
  export type ThreadDerivedFrom = z.infer<typeof threadDerivedFromSchema>;
@@ -270,11 +270,11 @@ export declare class ThreadStore {
270
270
  getContextRecovery(threadId: string): ContextRecoveryState | undefined;
271
271
  /** Historical ledger access; new task summaries do not add semantic facts. */
272
272
  getSemanticLedgerRows(threadId: string): {
273
- status: string;
273
+ item_id: string;
274
274
  generation: number;
275
275
  scope: string;
276
- category: "resource" | "decision" | "running_session" | "goal" | "constraint" | "completed_work" | "pending_work" | "uncertainty";
277
- item_id: string;
276
+ category: "decision" | "resource" | "running_session" | "goal" | "constraint" | "completed_work" | "pending_work" | "uncertainty";
277
+ status: string;
278
278
  first_tool_sequence: number;
279
279
  item_json: string;
280
280
  resolution_json?: string | null | undefined;
@@ -5,61 +5,15 @@ export declare const turnInputIdSchema: z.ZodString;
5
5
  export declare const turnInputSkillCheckpointSchema: z.ZodReadonly<z.ZodObject<{
6
6
  version: z.ZodLiteral<1>;
7
7
  kind: z.ZodLiteral<"explicit-skill">;
8
- } & {
9
- snapshot: z.ZodReadonly<z.ZodObject<Pick<{
10
- userPrompt: z.ZodString;
11
- skillNames: z.ZodArray<z.ZodString, "many">;
8
+ snapshot: z.ZodReadonly<z.ZodObject<{
12
9
  skills: z.ZodOptional<z.ZodArray<z.ZodReadonly<z.ZodObject<{
13
10
  name: z.ZodString;
14
11
  source: z.ZodString;
15
12
  contentSha256: z.ZodString;
16
- }, "strip", z.ZodTypeAny, {
17
- name: string;
18
- source: string;
19
- contentSha256: string;
20
- }, {
21
- name: string;
22
- source: string;
23
- contentSha256: string;
24
- }>>, "many">>;
25
- }, "skills" | "skillNames">, "strip", z.ZodTypeAny, {
26
- skillNames: string[];
27
- skills?: Readonly<{
28
- name: string;
29
- source: string;
30
- contentSha256: string;
31
- }>[] | undefined;
32
- }, {
33
- skillNames: string[];
34
- skills?: Readonly<{
35
- name: string;
36
- source: string;
37
- contentSha256: string;
38
- }>[] | undefined;
39
- }>>;
40
- }, "strip", z.ZodTypeAny, {
41
- kind: "explicit-skill";
42
- version: 1;
43
- snapshot: Readonly<{
44
- skillNames: string[];
45
- skills?: Readonly<{
46
- name: string;
47
- source: string;
48
- contentSha256: string;
49
- }>[] | undefined;
50
- }>;
51
- }, {
52
- kind: "explicit-skill";
53
- version: 1;
54
- snapshot: Readonly<{
55
- skillNames: string[];
56
- skills?: Readonly<{
57
- name: string;
58
- source: string;
59
- contentSha256: string;
60
- }>[] | undefined;
61
- }>;
62
- }>>;
13
+ }, z.core.$strip>>>>;
14
+ skillNames: z.ZodArray<z.ZodString>;
15
+ }, z.core.$strip>>;
16
+ }, z.core.$strip>>;
63
17
  export type TurnInputSkillCheckpoint = z.infer<typeof turnInputSkillCheckpointSchema>;
64
18
  export declare const acceptedTurnInputSchema: z.ZodReadonly<z.ZodObject<{
65
19
  inputId: z.ZodString;
@@ -68,94 +22,16 @@ export declare const acceptedTurnInputSchema: z.ZodReadonly<z.ZodObject<{
68
22
  skillCheckpoint: z.ZodOptional<z.ZodReadonly<z.ZodObject<{
69
23
  version: z.ZodLiteral<1>;
70
24
  kind: z.ZodLiteral<"explicit-skill">;
71
- } & {
72
- snapshot: z.ZodReadonly<z.ZodObject<Pick<{
73
- userPrompt: z.ZodString;
74
- skillNames: z.ZodArray<z.ZodString, "many">;
25
+ snapshot: z.ZodReadonly<z.ZodObject<{
75
26
  skills: z.ZodOptional<z.ZodArray<z.ZodReadonly<z.ZodObject<{
76
27
  name: z.ZodString;
77
28
  source: z.ZodString;
78
29
  contentSha256: z.ZodString;
79
- }, "strip", z.ZodTypeAny, {
80
- name: string;
81
- source: string;
82
- contentSha256: string;
83
- }, {
84
- name: string;
85
- source: string;
86
- contentSha256: string;
87
- }>>, "many">>;
88
- }, "skills" | "skillNames">, "strip", z.ZodTypeAny, {
89
- skillNames: string[];
90
- skills?: Readonly<{
91
- name: string;
92
- source: string;
93
- contentSha256: string;
94
- }>[] | undefined;
95
- }, {
96
- skillNames: string[];
97
- skills?: Readonly<{
98
- name: string;
99
- source: string;
100
- contentSha256: string;
101
- }>[] | undefined;
102
- }>>;
103
- }, "strip", z.ZodTypeAny, {
104
- kind: "explicit-skill";
105
- version: 1;
106
- snapshot: Readonly<{
107
- skillNames: string[];
108
- skills?: Readonly<{
109
- name: string;
110
- source: string;
111
- contentSha256: string;
112
- }>[] | undefined;
113
- }>;
114
- }, {
115
- kind: "explicit-skill";
116
- version: 1;
117
- snapshot: Readonly<{
118
- skillNames: string[];
119
- skills?: Readonly<{
120
- name: string;
121
- source: string;
122
- contentSha256: string;
123
- }>[] | undefined;
124
- }>;
125
- }>>>;
126
- }, "strip", z.ZodTypeAny, {
127
- createdAt: string;
128
- inputId: string;
129
- transcriptSequence: number;
130
- skillCheckpoint?: Readonly<{
131
- kind: "explicit-skill";
132
- version: 1;
133
- snapshot: Readonly<{
134
- skillNames: string[];
135
- skills?: Readonly<{
136
- name: string;
137
- source: string;
138
- contentSha256: string;
139
- }>[] | undefined;
140
- }>;
141
- }> | undefined;
142
- }, {
143
- createdAt: string;
144
- inputId: string;
145
- transcriptSequence: number;
146
- skillCheckpoint?: Readonly<{
147
- kind: "explicit-skill";
148
- version: 1;
149
- snapshot: Readonly<{
150
- skillNames: string[];
151
- skills?: Readonly<{
152
- name: string;
153
- source: string;
154
- contentSha256: string;
155
- }>[] | undefined;
156
- }>;
157
- }> | undefined;
158
- }>>;
30
+ }, z.core.$strip>>>>;
31
+ skillNames: z.ZodArray<z.ZodString>;
32
+ }, z.core.$strip>>;
33
+ }, z.core.$strip>>>;
34
+ }, z.core.$strip>>;
159
35
  export type AcceptedTurnInput = z.infer<typeof acceptedTurnInputSchema>;
160
36
  /** A transient evidence projection only. Never rewrite raw transcript or load Skill bodies. */
161
37
  export declare function projectTurnInputSkillCheckpoint(message: ModelMessage, checkpoint: TurnInputSkillCheckpoint | undefined): ModelMessage;
@@ -1 +1 @@
1
- import{z as t}from"zod";import{SKILL_INVOCATION_PARSE_KINDS as n,parseSkillInvocationResult as e}from"@roll-agent/core/skills/invocation";import{explicitSkillCheckpointV1Schema as o}from"../engine/explicit-skill-context.js";export const turnInputIdSchema=t.string().min(1).max(128);export const turnInputSkillCheckpointSchema=o.unwrap().extend({snapshot:o.unwrap().shape.snapshot.unwrap().pick({skillNames:!0,skills:!0}).readonly()}).readonly();export const acceptedTurnInputSchema=t.object({inputId:turnInputIdSchema,transcriptSequence:t.number().int().nonnegative(),createdAt:t.string().datetime(),skillCheckpoint:turnInputSkillCheckpointSchema.optional()}).readonly();export function projectTurnInputSkillCheckpoint(t,o){if(void 0===o||"user"!==t.role)return t;const r="string"==typeof t.content?t.content:t.content.filter(t=>"text"===t.type).map(t=>t.text).join("\n"),i=e(r,o.snapshot.skillNames.map(t=>({name:t,description:"",source:"project"}))),p=i.kind===n.valid?i.invocation.prompt:r;return{...t,providerOptions:{...t.providerOptions,rollHarness:{...t.providerOptions?.rollHarness,explicitSkillCheckpoint:{...o,snapshot:{...o.snapshot,userPrompt:p}}}}}}
1
+ import{z as t}from"zod";import{SKILL_INVOCATION_PARSE_KINDS as n,parseSkillInvocationResult as e}from"../skills/invocation.js";import{explicitSkillCheckpointV1Schema as o}from"../engine/explicit-skill-context.js";export const turnInputIdSchema=t.string().min(1).max(128);export const turnInputSkillCheckpointSchema=o.unwrap().extend({snapshot:o.unwrap().shape.snapshot.unwrap().pick({skillNames:!0,skills:!0}).readonly()}).readonly();export const acceptedTurnInputSchema=t.object({inputId:turnInputIdSchema,transcriptSequence:t.number().int().nonnegative(),createdAt:t.string().datetime(),skillCheckpoint:turnInputSkillCheckpointSchema.optional()}).readonly();export function projectTurnInputSkillCheckpoint(t,o){if(void 0===o||"user"!==t.role)return t;const i="string"==typeof t.content?t.content:t.content.filter(t=>"text"===t.type).map(t=>t.text).join("\n"),r=e(i,o.snapshot.skillNames.map(t=>({name:t,description:"",source:"project"}))),p=r.kind===n.valid?r.invocation.prompt:i;return{...t,providerOptions:{...t.providerOptions,rollHarness:{...t.providerOptions?.rollHarness,explicitSkillCheckpoint:{...o,snapshot:{...o.snapshot,userPrompt:p}}}}}}
@@ -36,19 +36,7 @@ declare const bashToolInputSchema: z.ZodObject<{
36
36
  workdir: z.ZodOptional<z.ZodString>;
37
37
  timeout_ms: z.ZodOptional<z.ZodNumber>;
38
38
  max_output_chars: z.ZodOptional<z.ZodNumber>;
39
- }, "strip", z.ZodTypeAny, {
40
- command: string;
41
- explanation?: string | undefined;
42
- workdir?: string | undefined;
43
- timeout_ms?: number | undefined;
44
- max_output_chars?: number | undefined;
45
- }, {
46
- command: string;
47
- explanation?: string | undefined;
48
- workdir?: string | undefined;
49
- timeout_ms?: number | undefined;
50
- max_output_chars?: number | undefined;
51
- }>;
39
+ }, z.core.$strip>;
52
40
  export type BashToolInput = z.infer<typeof bashToolInputSchema>;
53
41
  export declare function buildBashToolset(settings: SessionBashSettings, registry: ToolRegistry, ctx: BashToolContext, deps?: BashToolDeps): ToolSet;
54
42
  export {};
@@ -1,17 +1,17 @@
1
- import { type JsonSchemaRefIssue } from "@roll-agent/core/tool-runtime/json-schema-refs";
1
+ import { type JsonSchemaRefIssue } from "../tool-contracts/json-schema-refs.ts";
2
2
  import { type ToolSet } from "ai";
3
3
  import type { FileChangeDiff } from "@roll-agent/protocol";
4
4
  import type { ObservationRetentionDeclaration } from "@roll-agent/protocol/observation-retention";
5
5
  import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
6
- import type { AgentTool } from "@roll-agent/core/types/agent";
6
+ import type { AgentTool } from "../tool-contracts/agent-types.ts";
7
7
  import type { SessionApprovalMemory } from "../approval/approval-memory.ts";
8
8
  import type { ApprovalDecision } from "../approval/approval-gate.ts";
9
9
  import type { ToolAnnotations, ToolPolicy } from "../types/policy.ts";
10
10
  import { ToolRegistry, type ToolRouteMetadata } from "./naming.ts";
11
11
  import { type NormalizedToolResult } from "./normalize-result.ts";
12
12
  import { type ToolExecutionCoordinator, type ToolResourceHint } from "./tool-execution-coordinator.ts";
13
- export { readExecutionTimeoutMs, ROLL_EXECUTION_TIMEOUT_META_KEY, } from "@roll-agent/core/tool-runtime/execution-timeout";
14
- export declare const ROLL_RESOURCE_HINTS_META_KEY = "roll/resourceHints";
13
+ export { readExecutionTimeoutMs, ROLL_EXECUTION_TIMEOUT_META_KEY, } from "../tool-contracts/execution-timeout.ts";
14
+ export { ROLL_RESOURCE_HINTS_META_KEY } from "../tool-contracts/resource-hints.ts";
15
15
  export interface SourceTool {
16
16
  readonly tool: AgentTool;
17
17
  readonly annotations: ToolAnnotations | undefined;
@@ -20,7 +20,7 @@ export interface SourceTool {
20
20
  }
21
21
  export interface AgentToolSource {
22
22
  readonly agentName: string;
23
- readonly client: Client;
23
+ readonly client: Pick<Client, "callTool">;
24
24
  readonly tools: readonly SourceTool[];
25
25
  readonly agentSource?: ToolRouteMetadata["agentSource"];
26
26
  readonly transport?: ToolRouteMetadata["transport"];
@@ -1 +1 @@
1
- import{lstatSync as o,readdirSync as t,readlinkSync as e,realpathSync as n,statSync as r}from"node:fs";import{inlineAcyclicLocalJsonSchemaReferences as i}from"@roll-agent/core/tool-runtime/json-schema-refs";import{basename as s,dirname as a,isAbsolute as c,resolve as u}from"node:path";import{jsonSchema as l,tool as f}from"ai";import{preflightToolCall as p}from"@roll-agent/core/tool-runtime/preflight";import{readExecutionTimeoutMs as d,ROLL_EXECUTION_TIMEOUT_META_KEY as m}from"@roll-agent/core/tool-runtime/execution-timeout";import{ToolRegistry as v}from"./naming.js";import{TOOL_OUTCOME_KINDS as g,failedToolResult as y,toolResultToModelOutput as h}from"./normalize-result.js";import{TOOL_RESOURCE_ACCESS_MODES as S,TOOL_RESOURCE_HINT_KINDS as b,executeCoordinatedTool as $}from"./tool-execution-coordinator.js";import{executeWithToolApproval as w}from"./tool-approval-continuation.js";import{currentObservationModelOutput as O}from"../engine/observation-projection.js";export{readExecutionTimeoutMs,ROLL_EXECUTION_TIMEOUT_META_KEY}from"@roll-agent/core/tool-runtime/execution-timeout";export const ROLL_RESOURCE_HINTS_META_KEY="roll/resourceHints";function T(o,t){const e=new Map;for(const n of[...o??[],...t])e.set(`${n.path}\0${n.ref}`,n);return[...e.values()]}function C(o){return"object"!=typeof o||null===o||Array.isArray(o)?{}:o}function x(o){return`参数校验失败: ${o.map(o=>o.message).join("; ")}`}function N(o){return!0===o?.readOnlyHint&&!0!==o.destructiveHint?S.read:S.write}function E(o){return"string"==typeof o||"number"==typeof o?[o]:Array.isArray(o)&&0!==o.length&&o.every(o=>"string"==typeof o||"number"==typeof o)?o:void 0}const j=256,k=new Map;function A(o,t){for(let e=0;e<o.length;e+=1){const n=o.charCodeAt(e),r=n>=65&&n<=90?String.fromCharCode(n+32):n>=97&&n<=122?String.fromCharCode(n-32):void 0;if(void 0===r)continue;const i=`${o.slice(0,e)}${r}${o.slice(e+1)}`;if(!t.has(i))return i}}function I(o){return"object"==typeof o&&null!==o&&"code"in o?o.code:void 0}function M(t,e,n){const r=A(e,n);if(void 0!==r)try{const n=o(u(t,e)),i=o(u(t,r));return n.dev===i.dev&&n.ino===i.ino}catch(o){const t=I(o);return"ENOENT"!==t&&"ENOTDIR"!==t&&void 0}}function L(o,t){if(k.size>=j){const o=k.keys().next().value;void 0!==o&&k.delete(o)}return k.set(o,t),t}function R(e){const n=k.get(e);if(void 0!==n)return n;let r;try{r=o(e).dev}catch{return L(e,!0)}let i=e;for(;;){const n=k.get(i);if(void 0!==n)return L(e,n);try{const o=t(i),n=new Set(o);for(const t of o){const o=M(i,t,n);if(void 0!==o)return L(i,o),L(e,o)}}catch{}const s=a(i);if(s===i)break;try{if(o(s).dev!==r)break}catch{break}i=s}return L(e,!0)}function _(o){let t=o.normalize("NFC");for(let o=0;o<8;o+=1){const o=t.toUpperCase().toLowerCase().normalize("NFC");if(o===t)return t;t=o}return t}function D(o,t){try{const e=r(o,{bigint:!0}),n=t.map(o=>_(o));return`file-unresolved-alias:${e.dev.toString()}:${e.ino.toString()}:${JSON.stringify(n)}`}catch{return}}function K(t,r=new Set){let i=t;const c=[];for(;;)try{const o=n.native(i),t=c.reverse().map(o=>o.normalize("NFC"));if(0===t.length)return{path:o};const e=R(o),r=u(o,...e?t.map(o=>o.toLowerCase()):t),s=e?D(o,t):void 0;return{path:r,...void 0===s?{}:{unresolvedAliasKey:s}}}catch{try{if(o(i).isSymbolicLink()&&!r.has(i)){const o=new Set(r);o.add(i);const t=e(i);return K(u(a(i),t,...[...c].reverse()),o)}}catch{}const n=a(i);if(n===i)return{path:t};c.push(s(i)),i=n}}function z(o){try{const t=r(o,{bigint:!0});return`file-inode:${t.dev.toString()}:${t.ino.toString()}`}catch{return}}function H(o,t,e){const n=String(t).trim();if(0!==n.length)switch(o.kind){case b.file:{if(!c(n)&&void 0===e)return;const o=K(u(e??"/",n)),t=z(o.path);return[`file:${o.path}`,...void 0===o.unresolvedAliasKey?[]:[o.unresolvedAliasKey],...void 0===t?[]:[t]]}case b.browserSession:return[`browser-session:${n}`];case b.conversation:return[`conversation:${n}`];case b.custom:{const t=o.namespace?.trim();return t?[`${t}:${n}`]:void 0}}}function G(o,t,e,n,r){const i=N(n),s=C(e),a=[{key:`agent:${o}`,mode:i}],c=[];for(const o of r??[]){if(!Object.hasOwn(s,o.field))continue;const e=E(s[o.field]);if(void 0===e)return a;for(const n of e){const e=H(o,n,t);if(void 0===e||0===e.length)return a;c.push(...e.map(t=>({key:t,mode:o.mode??i})))}}return 0===c.length?a:[{key:`agent:${o}`,mode:S.read},...c]}export async function gateToolCall(o,t,e,n,r,i){if(!o.policy)return;const s=o.policy.check({agentName:t,toolName:e,input:n,...r?{annotations:r}:{}});if("deny"===s.action)return y(g.policyDenied,"策略拒绝执行"+(s.reason?`: ${s.reason}`:""),s.reason?{reason:s.reason}:{});if("confirm"===s.action){const r=i?.memoryKey;if(void 0!==r&&o.approvalMemory?.isGranted(r))return;const a=await o.requestApproval({agentName:t,toolName:e,input:n,reason:!1===i?.includePolicyReason?void 0:s.reason,...void 0!==i?.explanation?{explanation:i.explanation}:{},...void 0!==i?.diff?{diff:i.diff}:{},...void 0!==i?.fullDiff?{fullDiff:i.fullDiff}:{},...void 0!==r&&void 0!==i?.sessionGrantLabel?{sessionGrantLabel:i.sessionGrantLabel}:{}});if(!a.approved)return y(g.userRejected,"已取消执行"+(a.reason?`: ${a.reason}`:""),a.reason?{reason:a.reason}:{});void 0!==r&&"session"===a.scope&&o.approvalMemory?.grant(r)}}export function buildAgentToolset(o,t,e=new v){const n={},r={},s=new Map;for(const a of o){const{client:o,agentName:c,agentSource:u,transport:v,runtimeOwnership:S,resourceBaseDir:b}=a;for(const{tool:N,annotations:E,resourceHints:j,observationRetention:k}of a.tools){const a=i(N.inputSchema),A=T(N.schemaIssues,a.unresolved),I={...N,inputSchema:a.schema,...A.length>0?{schemaIssues:A}:{}},M=e.register(c,I.name,{...u?{agentSource:u}:{},...v?{transport:v}:{},...S?{runtimeOwnership:S}:{},...E?{annotations:E}:{},...I.appOutput?{appOutput:I.appOutput}:{}});A.length>0&&(r[M]=A),k&&s.set(M,k);const L={prepare:async o=>{const e=C(o),n=p(I,e);return n.ok?gateToolCall(t,c,I.name,e,E):y(g.invalidInput,x(n.issues),{raw:n.issues})},resources:o=>G(c,b,o,E,j)};t.coordinator?.register(M,L),n[M]=f({description:I.description??`${I.name} (via ${c})`,inputSchema:l(I.inputSchema),toModelOutput:({output:o})=>o.outcome.kind===g.success?O(o.raw,k)??h(o):h(o),execute:async(e,n)=>{const r=C(e);return $(t.coordinator,L,M,n.toolCallId,r,n.abortSignal,async()=>{const e=d({[m]:I.executionTimeoutMs}),i=n.abortSignal||void 0!==e?{...n.abortSignal?{signal:n.abortSignal}:{},...void 0===e?{}:{timeout:e}}:void 0;return w({input:r,agentName:c,agentTool:I,annotations:E,ctx:t,signal:n.abortSignal,call:async t=>await o.callTool({name:I.name,arguments:t},void 0,i)})})}})}}return{tools:n,registry:e,schemaIssuesByToolId:r,observationRetentionByToolId:s}}
1
+ import{lstatSync as o,readdirSync as t,readlinkSync as e,realpathSync as n,statSync as r}from"node:fs";import{inlineAcyclicLocalJsonSchemaReferences as i}from"../tool-contracts/json-schema-refs.js";import{basename as s,dirname as a,isAbsolute as c,resolve as u}from"node:path";import{jsonSchema as l,tool as f}from"ai";import{preflightToolCall as p}from"../tool-contracts/preflight.js";import{modelToolInputSchema as d}from"./model-input-schema.js";import{readExecutionTimeoutMs as m,ROLL_EXECUTION_TIMEOUT_META_KEY as v}from"../tool-contracts/execution-timeout.js";import{ToolRegistry as g}from"./naming.js";import{TOOL_OUTCOME_KINDS as h,failedToolResult as y,toolResultToModelOutput as S}from"./normalize-result.js";import{TOOL_RESOURCE_ACCESS_MODES as b,TOOL_RESOURCE_HINT_KINDS as $,executeCoordinatedTool as w}from"./tool-execution-coordinator.js";import{executeWithToolApproval as j}from"./tool-approval-continuation.js";import{currentObservationModelOutput as O}from"../engine/observation-projection.js";export{readExecutionTimeoutMs,ROLL_EXECUTION_TIMEOUT_META_KEY}from"../tool-contracts/execution-timeout.js";export{ROLL_RESOURCE_HINTS_META_KEY}from"../tool-contracts/resource-hints.js";function T(o,t){const e=new Map;for(const n of[...o??[],...t])e.set(`${n.path}\0${n.ref}`,n);return[...e.values()]}function C(o){return"object"!=typeof o||null===o||Array.isArray(o)?{}:o}function x(o){return`参数校验失败: ${o.map(o=>o.message).join("; ")}`}function N(o){return!0===o?.readOnlyHint&&!0!==o.destructiveHint?b.read:b.write}function E(o){return"string"==typeof o||"number"==typeof o?[o]:Array.isArray(o)&&0!==o.length&&o.every(o=>"string"==typeof o||"number"==typeof o)?o:void 0}const k=256,A=new Map;function I(o,t){for(let e=0;e<o.length;e+=1){const n=o.charCodeAt(e),r=n>=65&&n<=90?String.fromCharCode(n+32):n>=97&&n<=122?String.fromCharCode(n-32):void 0;if(void 0===r)continue;const i=`${o.slice(0,e)}${r}${o.slice(e+1)}`;if(!t.has(i))return i}}function M(o){return"object"==typeof o&&null!==o&&"code"in o?o.code:void 0}function L(t,e,n){const r=I(e,n);if(void 0!==r)try{const n=o(u(t,e)),i=o(u(t,r));return n.dev===i.dev&&n.ino===i.ino}catch(o){const t=M(o);return"ENOENT"!==t&&"ENOTDIR"!==t&&void 0}}function R(o,t){if(A.size>=k){const o=A.keys().next().value;void 0!==o&&A.delete(o)}return A.set(o,t),t}function _(e){const n=A.get(e);if(void 0!==n)return n;let r;try{r=o(e).dev}catch{return R(e,!0)}let i=e;for(;;){const n=A.get(i);if(void 0!==n)return R(e,n);try{const o=t(i),n=new Set(o);for(const t of o){const o=L(i,t,n);if(void 0!==o)return R(i,o),R(e,o)}}catch{}const s=a(i);if(s===i)break;try{if(o(s).dev!==r)break}catch{break}i=s}return R(e,!0)}function D(o){let t=o.normalize("NFC");for(let o=0;o<8;o+=1){const o=t.toUpperCase().toLowerCase().normalize("NFC");if(o===t)return t;t=o}return t}function K(o,t){try{const e=r(o,{bigint:!0}),n=t.map(o=>D(o));return`file-unresolved-alias:${e.dev.toString()}:${e.ino.toString()}:${JSON.stringify(n)}`}catch{return}}function z(t,r=new Set){let i=t;const c=[];for(;;)try{const o=n.native(i),t=c.reverse().map(o=>o.normalize("NFC"));if(0===t.length)return{path:o};const e=_(o),r=u(o,...e?t.map(o=>o.toLowerCase()):t),s=e?K(o,t):void 0;return{path:r,...void 0===s?{}:{unresolvedAliasKey:s}}}catch{try{if(o(i).isSymbolicLink()&&!r.has(i)){const o=new Set(r);o.add(i);const t=e(i);return z(u(a(i),t,...[...c].reverse()),o)}}catch{}const n=a(i);if(n===i)return{path:t};c.push(s(i)),i=n}}function G(o){try{const t=r(o,{bigint:!0});return`file-inode:${t.dev.toString()}:${t.ino.toString()}`}catch{return}}function H(o,t,e){const n=String(t).trim();if(0!==n.length)switch(o.kind){case $.file:{if(!c(n)&&void 0===e)return;const o=z(u(e??"/",n)),t=G(o.path);return[`file:${o.path}`,...void 0===o.unresolvedAliasKey?[]:[o.unresolvedAliasKey],...void 0===t?[]:[t]]}case $.browserSession:return[`browser-session:${n}`];case $.conversation:return[`conversation:${n}`];case $.custom:{const t=o.namespace?.trim();return t?[`${t}:${n}`]:void 0}}}function U(o,t,e,n,r){const i=N(n),s=C(e),a=[{key:`agent:${o}`,mode:i}],c=[];for(const o of r??[]){if(!Object.hasOwn(s,o.field))continue;const e=E(s[o.field]);if(void 0===e)return a;for(const n of e){const e=H(o,n,t);if(void 0===e||0===e.length)return a;c.push(...e.map(t=>({key:t,mode:o.mode??i})))}}return 0===c.length?a:[{key:`agent:${o}`,mode:b.read},...c]}export async function gateToolCall(o,t,e,n,r,i){if(!o.policy)return;const s=o.policy.check({agentName:t,toolName:e,input:n,...r?{annotations:r}:{}});if("deny"===s.action)return y(h.policyDenied,"策略拒绝执行"+(s.reason?`: ${s.reason}`:""),s.reason?{reason:s.reason}:{});if("confirm"===s.action){const r=i?.memoryKey;if(void 0!==r&&o.approvalMemory?.isGranted(r))return;const a=await o.requestApproval({agentName:t,toolName:e,input:n,reason:!1===i?.includePolicyReason?void 0:s.reason,...void 0!==i?.explanation?{explanation:i.explanation}:{},...void 0!==i?.diff?{diff:i.diff}:{},...void 0!==i?.fullDiff?{fullDiff:i.fullDiff}:{},...void 0!==r&&void 0!==i?.sessionGrantLabel?{sessionGrantLabel:i.sessionGrantLabel}:{}});if(!a.approved)return y(h.userRejected,"已取消执行"+(a.reason?`: ${a.reason}`:""),a.reason?{reason:a.reason}:{});void 0!==r&&"session"===a.scope&&o.approvalMemory?.grant(r)}}export function buildAgentToolset(o,t,e=new g){const n={},r={},s=new Map;for(const a of o){const{client:o,agentName:c,agentSource:u,transport:g,runtimeOwnership:b,resourceBaseDir:$}=a;for(const{tool:N,annotations:E,resourceHints:k,observationRetention:A}of a.tools){const a=i(N.inputSchema),I=T(N.schemaIssues,a.unresolved),M={...N,inputSchema:a.schema,...I.length>0?{schemaIssues:I}:{}},L=e.register(c,M.name,{...u?{agentSource:u}:{},...g?{transport:g}:{},...b?{runtimeOwnership:b}:{},...E?{annotations:E}:{},...M.appOutput?{appOutput:M.appOutput}:{}});I.length>0&&(r[L]=I),A&&s.set(L,A);const R={prepare:async o=>{const e=C(o),n=p(M,e);return n.ok?gateToolCall(t,c,M.name,e,E):y(h.invalidInput,x(n.issues),{raw:n.issues})},resources:o=>U(c,$,o,E,k)};t.coordinator?.register(L,R),n[L]=f({description:M.description??`${M.name} (via ${c})`,inputSchema:d(l(M.inputSchema)),toModelOutput:({output:o})=>o.outcome.kind===h.success?O(o.raw,A)??S(o):S(o),execute:async(e,n)=>{const r=C(e);return w(t.coordinator,R,L,n.toolCallId,r,n.abortSignal,async()=>{const e=m({[v]:M.executionTimeoutMs}),i=n.abortSignal||void 0!==e?{...n.abortSignal?{signal:n.abortSignal}:{},...void 0===e?{}:{timeout:e}}:void 0;return j({input:r,agentName:c,agentTool:M,annotations:E,ctx:t,signal:n.abortSignal,call:async t=>await o.callTool({name:M.name,arguments:t},void 0,i)})})}})}}return{tools:n,registry:e,schemaIssuesByToolId:r,observationRetentionByToolId:s}}