@temporalio/agent-harness 0.0.0-stage → 0.2.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 (74) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -2
  3. package/dist/src/ai-sdks/google-genai-plugin/index.d.ts +6 -0
  4. package/dist/src/ai-sdks/google-genai-plugin/index.js +24 -0
  5. package/dist/src/ai-sdks/google-genai-plugin/interactions-conversation.d.ts +35 -0
  6. package/dist/src/ai-sdks/google-genai-plugin/interactions-conversation.js +178 -0
  7. package/dist/src/ai-sdks/google-genai-plugin/interactions-models.d.ts +8 -0
  8. package/dist/src/ai-sdks/google-genai-plugin/interactions-models.js +4 -0
  9. package/dist/src/ai-sdks/google-genai-plugin/interactions-workflow.d.ts +8 -0
  10. package/dist/src/ai-sdks/google-genai-plugin/interactions-workflow.js +15 -0
  11. package/dist/src/ai-sdks/google-genai-plugin/temporal-async-client.d.ts +10 -0
  12. package/dist/src/ai-sdks/google-genai-plugin/temporal-async-client.js +9 -0
  13. package/dist/src/ai-sdks/google-genai-plugin/temporal-interactions.d.ts +31 -0
  14. package/dist/src/ai-sdks/google-genai-plugin/temporal-interactions.js +43 -0
  15. package/dist/src/ai-sdks/google-genai-plugin/workflow.d.ts +16 -0
  16. package/dist/src/ai-sdks/google-genai-plugin/workflow.js +14 -0
  17. package/dist/src/ai-sdks/jev/evaluator.d.ts +38 -0
  18. package/dist/src/ai-sdks/jev/evaluator.js +155 -0
  19. package/dist/src/ai-sdks/openai-agents-harness.d.ts +94 -0
  20. package/dist/src/ai-sdks/openai-agents-harness.js +347 -0
  21. package/dist/src/harness/agent-protocol/agent-interface.d.ts +369 -0
  22. package/dist/src/harness/agent-protocol/agent-interface.js +222 -0
  23. package/dist/src/harness/agent-protocol/events.d.ts +10 -0
  24. package/dist/src/harness/agent-protocol/events.js +6 -0
  25. package/dist/src/harness/agent-protocol/index.d.ts +5 -0
  26. package/dist/src/harness/agent-protocol/index.js +7 -0
  27. package/dist/src/harness/agent-protocol/schema.d.ts +34 -0
  28. package/dist/src/harness/agent-protocol/schema.js +53 -0
  29. package/dist/src/harness/agent-protocol/subagent-interface.d.ts +25 -0
  30. package/dist/src/harness/agent-protocol/subagent-interface.js +17 -0
  31. package/dist/src/harness/agent-schema.d.ts +4 -0
  32. package/dist/src/harness/agent-schema.js +106 -0
  33. package/dist/src/harness/agent-workflow/errors.d.ts +26 -0
  34. package/dist/src/harness/agent-workflow/errors.js +67 -0
  35. package/dist/src/harness/agent-workflow/types.d.ts +88 -0
  36. package/dist/src/harness/agent-workflow/types.js +1 -0
  37. package/dist/src/harness/agent-workflow.d.ts +79 -0
  38. package/dist/src/harness/agent-workflow.js +824 -0
  39. package/dist/src/harness/agent.d.ts +137 -0
  40. package/dist/src/harness/agent.js +272 -0
  41. package/dist/src/harness/code-mode/activity-fs.d.ts +46 -0
  42. package/dist/src/harness/code-mode/activity-fs.js +102 -0
  43. package/dist/src/harness/code-mode/base64.d.ts +2 -0
  44. package/dist/src/harness/code-mode/base64.js +41 -0
  45. package/dist/src/harness/code-mode/driver.d.ts +78 -0
  46. package/dist/src/harness/code-mode/driver.js +266 -0
  47. package/dist/src/harness/code-mode/index.d.ts +4 -0
  48. package/dist/src/harness/code-mode/index.js +6 -0
  49. package/dist/src/harness/code-mode/mount-decl.d.ts +43 -0
  50. package/dist/src/harness/code-mode/mount-decl.js +100 -0
  51. package/dist/src/harness/code-mode/okf-tool.d.ts +10 -0
  52. package/dist/src/harness/code-mode/okf-tool.js +89 -0
  53. package/dist/src/harness/code-mode/okf.d.ts +91 -0
  54. package/dist/src/harness/code-mode/okf.js +315 -0
  55. package/dist/src/harness/code-mode/stubs.d.ts +13 -0
  56. package/dist/src/harness/code-mode/stubs.js +203 -0
  57. package/dist/src/harness/code-mode/texts.d.ts +4 -0
  58. package/dist/src/harness/code-mode/texts.js +6 -0
  59. package/dist/src/harness/code-mode/tool.d.ts +37 -0
  60. package/dist/src/harness/code-mode/tool.js +79 -0
  61. package/dist/src/harness/code-mode/vfs.d.ts +209 -0
  62. package/dist/src/harness/code-mode/vfs.js +862 -0
  63. package/dist/src/harness/py-repr.d.ts +2 -0
  64. package/dist/src/harness/py-repr.js +24 -0
  65. package/dist/src/harness/state/index.d.ts +40 -0
  66. package/dist/src/harness/state/index.js +142 -0
  67. package/dist/src/harness/stream-context.d.ts +8 -0
  68. package/dist/src/harness/stream-context.js +9 -0
  69. package/dist/src/harness/subagent-toolset.d.ts +29 -0
  70. package/dist/src/harness/subagent-toolset.js +87 -0
  71. package/dist/src/index.d.ts +12 -0
  72. package/dist/src/index.js +13 -0
  73. package/dist/src/sandbox.d.ts +12 -0
  74. package/package.json +95 -3
@@ -0,0 +1,369 @@
1
+ import { z } from "zod";
2
+ export declare const SEND_AGENT_MESSAGE_UPDATE = "send_agent_message";
3
+ export declare const TOOL_APPROVAL_UPDATE = "tool_approval";
4
+ export declare const PROVIDE_CALLBACK_RESULT_UPDATE = "provide_callback_result";
5
+ export declare const AGENT_STATUS_QUERY = "agent_status";
6
+ export declare const AGENT_INTERFACE_QUERY = "agent_interface";
7
+ export declare const CLOSE_SIGNAL = "close";
8
+ export declare const AGENT_ID_LENGTH = 6;
9
+ export declare const APPROVAL_SHORT_ID_LENGTH = 6;
10
+ export declare const MidTurn: {
11
+ readonly ENQUEUE: "enqueue";
12
+ readonly REJECT: "reject";
13
+ readonly ACCEPT: "accept";
14
+ };
15
+ export type MidTurn = (typeof MidTurn)[keyof typeof MidTurn];
16
+ export declare const MessageDisposition: {
17
+ readonly OPENED: "opened";
18
+ readonly JOINED: "joined";
19
+ readonly QUEUED: "queued";
20
+ };
21
+ export type MessageDisposition = (typeof MessageDisposition)[keyof typeof MessageDisposition];
22
+ /** What an auto-mode evaluator decides, named after AI SDK 7's tool-approval outcomes. */
23
+ export declare const ApprovalVerdict: {
24
+ readonly APPROVED: "approved";
25
+ readonly DENIED: "denied";
26
+ readonly USER_APPROVAL: "user-approval";
27
+ readonly NOT_APPLICABLE: "not-applicable";
28
+ };
29
+ export type ApprovalVerdict = (typeof ApprovalVerdict)[keyof typeof ApprovalVerdict];
30
+ /** The verdict as it goes on the wire (auto_approval_evaluation_* events), as in Python. */
31
+ export declare const AutoApprovalVerdict: {
32
+ readonly APPROVE: "approve";
33
+ readonly DENY: "deny";
34
+ readonly ESCALATE: "escalate";
35
+ };
36
+ export type AutoApprovalVerdict = (typeof AutoApprovalVerdict)[keyof typeof AutoApprovalVerdict];
37
+ /** Both of the evaluator's "not mine to decide" outcomes leave the call to a human. */
38
+ export declare const WIRE_VERDICT: Readonly<Record<ApprovalVerdict, AutoApprovalVerdict>>;
39
+ export declare const ToolApprovalPolicySchema: z.ZodObject<{
40
+ dangerously_skip_all_approvals: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<0 | 1>, z.ZodString]>, z.ZodTransform<boolean, string | 0 | 1 | boolean>>>;
41
+ auto_approve_inherently_safe: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<0 | 1>, z.ZodString]>, z.ZodTransform<boolean, string | 0 | 1 | boolean>>>;
42
+ auto_approve_tools: z.ZodPipe<z.ZodDefault<z.ZodArray<z.ZodString>>, z.ZodTransform<string[], string[]>>;
43
+ auto_mode_enabled: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<0 | 1>, z.ZodString]>, z.ZodTransform<boolean, string | 0 | 1 | boolean>>>;
44
+ }, z.core.$strict>;
45
+ export type ToolApprovalPolicy = z.output<typeof ToolApprovalPolicySchema>;
46
+ export declare const ToolApprovalPolicy: {
47
+ parse: (value: unknown) => ToolApprovalPolicy;
48
+ alwaysRequireHumanApproval: () => ToolApprovalPolicy;
49
+ allowInherentlySafe: () => ToolApprovalPolicy;
50
+ allowTools: (tools: Iterable<string>, { alsoInherentlySafe }?: {
51
+ alsoInherentlySafe?: boolean | undefined;
52
+ }) => ToolApprovalPolicy;
53
+ autoMode: ({ preApprovedTools, preApproveInherentlySafe, }?: {
54
+ preApproveInherentlySafe?: boolean | undefined;
55
+ preApprovedTools?: Iterable<string> | undefined;
56
+ }) => ToolApprovalPolicy;
57
+ dangerouslySkipAll: () => ToolApprovalPolicy;
58
+ withChanges: (policy: ToolApprovalPolicy, changes: Partial<ToolApprovalPolicy>) => ToolApprovalPolicy;
59
+ withToolAllowed: (policy: ToolApprovalPolicy, toolName: string) => ToolApprovalPolicy;
60
+ withAutoMode: (policy: ToolApprovalPolicy, enabled: boolean) => ToolApprovalPolicy;
61
+ /** Layers 0-2: dispatch with no gate and no approval events at all. */
62
+ autoApproves(policy: ToolApprovalPolicy, toolName: string, { inherentlySafe }: {
63
+ inherentlySafe: boolean;
64
+ }): boolean;
65
+ /** Layer 3: whether a call the static layers did not approve goes to the auto mode evaluator. */
66
+ consultsAutoMode(policy: ToolApprovalPolicy, toolName: string, opts: {
67
+ inherentlySafe: boolean;
68
+ }): boolean;
69
+ };
70
+ export declare const AutoApprovalCriteriaSetSchema: z.ZodObject<{
71
+ effect: z.ZodDefault<z.ZodNullable<z.ZodString>>;
72
+ approve_when: z.ZodDefault<z.ZodArray<z.ZodString>>;
73
+ deny_when: z.ZodDefault<z.ZodArray<z.ZodString>>;
74
+ escalate_when: z.ZodDefault<z.ZodArray<z.ZodString>>;
75
+ min_confidence: z.ZodDefault<z.ZodNullable<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString]>, z.ZodTransform<number, string | number | boolean>>, z.ZodNumber>>>;
76
+ escalate_if_irreversible_above: z.ZodDefault<z.ZodNullable<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString]>, z.ZodTransform<number, string | number | boolean>>, z.ZodNumber>>>;
77
+ }, z.core.$strip>;
78
+ export type AutoApprovalCriteriaSet = z.output<typeof AutoApprovalCriteriaSetSchema>;
79
+ export declare const AutoApprovalCriteriaSchema: z.ZodObject<{
80
+ sets: z.ZodPrefault<z.ZodPipe<z.ZodPreprocess<z.ZodMap<z.ZodString, z.ZodObject<{
81
+ effect: z.ZodDefault<z.ZodNullable<z.ZodString>>;
82
+ approve_when: z.ZodDefault<z.ZodArray<z.ZodString>>;
83
+ deny_when: z.ZodDefault<z.ZodArray<z.ZodString>>;
84
+ escalate_when: z.ZodDefault<z.ZodArray<z.ZodString>>;
85
+ min_confidence: z.ZodDefault<z.ZodNullable<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString]>, z.ZodTransform<number, string | number | boolean>>, z.ZodNumber>>>;
86
+ escalate_if_irreversible_above: z.ZodDefault<z.ZodNullable<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString]>, z.ZodTransform<number, string | number | boolean>>, z.ZodNumber>>>;
87
+ }, z.core.$strip>>, unknown>, z.ZodTransform<Record<string, {
88
+ effect: string | null;
89
+ approve_when: string[];
90
+ deny_when: string[];
91
+ escalate_when: string[];
92
+ min_confidence: number | null;
93
+ escalate_if_irreversible_above: number | null;
94
+ }> & {
95
+ [k: string]: {
96
+ effect: string | null;
97
+ approve_when: string[];
98
+ deny_when: string[];
99
+ escalate_when: string[];
100
+ min_confidence: number | null;
101
+ escalate_if_irreversible_above: number | null;
102
+ };
103
+ }, Map<string, {
104
+ effect: string | null;
105
+ approve_when: string[];
106
+ deny_when: string[];
107
+ escalate_when: string[];
108
+ min_confidence: number | null;
109
+ escalate_if_irreversible_above: number | null;
110
+ }>>>>;
111
+ tools: z.ZodPrefault<z.ZodPipe<z.ZodPreprocess<z.ZodMap<z.ZodString, z.ZodString>, unknown>, z.ZodTransform<Record<string, string> & {
112
+ [k: string]: string;
113
+ }, Map<string, string>>>>;
114
+ default: z.ZodDefault<z.ZodNullable<z.ZodString>>;
115
+ context: z.ZodPrefault<z.ZodPipe<z.ZodPreprocess<z.ZodMap<z.ZodString, z.ZodUnknown>, unknown>, z.ZodTransform<Record<string, unknown> & {
116
+ [k: string]: unknown;
117
+ }, Map<string, unknown>>>>;
118
+ min_confidence: z.ZodDefault<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString]>, z.ZodTransform<number, string | number | boolean>>, z.ZodNumber>>;
119
+ escalate_if_irreversible_above: z.ZodDefault<z.ZodNullable<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString]>, z.ZodTransform<number, string | number | boolean>>, z.ZodNumber>>>;
120
+ }, z.core.$strip>;
121
+ export type AutoApprovalCriteria = z.output<typeof AutoApprovalCriteriaSchema>;
122
+ export type Thresholds = readonly [
123
+ minConfidence: number,
124
+ escalateIfIrreversibleAbove: number | null
125
+ ];
126
+ export declare const AutoApprovalCriteria: {
127
+ parse: (value: unknown) => AutoApprovalCriteria;
128
+ empty: () => AutoApprovalCriteria;
129
+ criteriaSet: (value: z.input<typeof AutoApprovalCriteriaSetSchema>) => AutoApprovalCriteriaSet;
130
+ isEmptySet: (s: AutoApprovalCriteriaSet) => boolean;
131
+ /** Precedence: runtime/config assignment, then the tool's declared set, then the catch-all. */
132
+ setNameFor: (c: AutoApprovalCriteria, toolName: string, declared?: string | null) => string | null;
133
+ /** The set judging `toolName`, or null when there is nothing to judge against (escalate). */
134
+ forTool(c: AutoApprovalCriteria, toolName: string, declared?: string | null): AutoApprovalCriteriaSet | null;
135
+ thresholdsForSet(c: AutoApprovalCriteria, s: AutoApprovalCriteriaSet | null): Thresholds;
136
+ withSet: (c: AutoApprovalCriteria, name: string, s: AutoApprovalCriteriaSet) => AutoApprovalCriteria;
137
+ withToolAssigned: (c: AutoApprovalCriteria, toolName: string, setName: string) => AutoApprovalCriteria;
138
+ };
139
+ export interface AutoApprovalDecision {
140
+ verdict: ApprovalVerdict;
141
+ reason?: string | null;
142
+ details?: Record<string, unknown>;
143
+ }
144
+ export interface AutoApprovalContext {
145
+ tool_name: string;
146
+ tool_input: Record<string, unknown>;
147
+ inherently_safe: boolean;
148
+ tool_description: string | null;
149
+ criteria: AutoApprovalCriteria;
150
+ criteria_version: number;
151
+ criteria_set: AutoApprovalCriteriaSet;
152
+ criteria_set_name: string;
153
+ thresholds: Thresholds;
154
+ }
155
+ /** Async on purpose: the gate races it against a human and cancels the loser. */
156
+ export type AutoModeEvaluator = ((ctx: AutoApprovalContext) => Promise<AutoApprovalDecision>) & {
157
+ /** Published as `evaluator` on the evaluation events; defaults to the function name. */
158
+ evaluatorLabel?: string;
159
+ };
160
+ export declare const AgentConfigSchema: z.ZodObject<{
161
+ approval_policy: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodObject<{
162
+ dangerously_skip_all_approvals: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<0 | 1>, z.ZodString]>, z.ZodTransform<boolean, string | 0 | 1 | boolean>>>;
163
+ auto_approve_inherently_safe: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<0 | 1>, z.ZodString]>, z.ZodTransform<boolean, string | 0 | 1 | boolean>>>;
164
+ auto_approve_tools: z.ZodPipe<z.ZodDefault<z.ZodArray<z.ZodString>>, z.ZodTransform<string[], string[]>>;
165
+ auto_mode_enabled: z.ZodDefault<z.ZodPipe<z.ZodUnion<readonly [z.ZodBoolean, z.ZodLiteral<0 | 1>, z.ZodString]>, z.ZodTransform<boolean, string | 0 | 1 | boolean>>>;
166
+ }, z.core.$strict>>>, z.ZodTransform<{
167
+ dangerously_skip_all_approvals: boolean;
168
+ auto_approve_inherently_safe: boolean;
169
+ auto_approve_tools: string[];
170
+ auto_mode_enabled: boolean;
171
+ } | null, {
172
+ dangerously_skip_all_approvals: boolean;
173
+ auto_approve_inherently_safe: boolean;
174
+ auto_approve_tools: string[];
175
+ auto_mode_enabled: boolean;
176
+ } | null | undefined>>;
177
+ auto_approval_criteria: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodObject<{
178
+ sets: z.ZodPrefault<z.ZodPipe<z.ZodPreprocess<z.ZodMap<z.ZodString, z.ZodObject<{
179
+ effect: z.ZodDefault<z.ZodNullable<z.ZodString>>;
180
+ approve_when: z.ZodDefault<z.ZodArray<z.ZodString>>;
181
+ deny_when: z.ZodDefault<z.ZodArray<z.ZodString>>;
182
+ escalate_when: z.ZodDefault<z.ZodArray<z.ZodString>>;
183
+ min_confidence: z.ZodDefault<z.ZodNullable<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString]>, z.ZodTransform<number, string | number | boolean>>, z.ZodNumber>>>;
184
+ escalate_if_irreversible_above: z.ZodDefault<z.ZodNullable<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString]>, z.ZodTransform<number, string | number | boolean>>, z.ZodNumber>>>;
185
+ }, z.core.$strip>>, unknown>, z.ZodTransform<Record<string, {
186
+ effect: string | null;
187
+ approve_when: string[];
188
+ deny_when: string[];
189
+ escalate_when: string[];
190
+ min_confidence: number | null;
191
+ escalate_if_irreversible_above: number | null;
192
+ }> & {
193
+ [k: string]: {
194
+ effect: string | null;
195
+ approve_when: string[];
196
+ deny_when: string[];
197
+ escalate_when: string[];
198
+ min_confidence: number | null;
199
+ escalate_if_irreversible_above: number | null;
200
+ };
201
+ }, Map<string, {
202
+ effect: string | null;
203
+ approve_when: string[];
204
+ deny_when: string[];
205
+ escalate_when: string[];
206
+ min_confidence: number | null;
207
+ escalate_if_irreversible_above: number | null;
208
+ }>>>>;
209
+ tools: z.ZodPrefault<z.ZodPipe<z.ZodPreprocess<z.ZodMap<z.ZodString, z.ZodString>, unknown>, z.ZodTransform<Record<string, string> & {
210
+ [k: string]: string;
211
+ }, Map<string, string>>>>;
212
+ default: z.ZodDefault<z.ZodNullable<z.ZodString>>;
213
+ context: z.ZodPrefault<z.ZodPipe<z.ZodPreprocess<z.ZodMap<z.ZodString, z.ZodUnknown>, unknown>, z.ZodTransform<Record<string, unknown> & {
214
+ [k: string]: unknown;
215
+ }, Map<string, unknown>>>>;
216
+ min_confidence: z.ZodDefault<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString]>, z.ZodTransform<number, string | number | boolean>>, z.ZodNumber>>;
217
+ escalate_if_irreversible_above: z.ZodDefault<z.ZodNullable<z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString]>, z.ZodTransform<number, string | number | boolean>>, z.ZodNumber>>>;
218
+ }, z.core.$strip>>>, z.ZodTransform<{
219
+ sets: Record<string, {
220
+ effect: string | null;
221
+ approve_when: string[];
222
+ deny_when: string[];
223
+ escalate_when: string[];
224
+ min_confidence: number | null;
225
+ escalate_if_irreversible_above: number | null;
226
+ }> & {
227
+ [k: string]: {
228
+ effect: string | null;
229
+ approve_when: string[];
230
+ deny_when: string[];
231
+ escalate_when: string[];
232
+ min_confidence: number | null;
233
+ escalate_if_irreversible_above: number | null;
234
+ };
235
+ };
236
+ tools: Record<string, string> & {
237
+ [k: string]: string;
238
+ };
239
+ default: string | null;
240
+ context: Record<string, unknown> & {
241
+ [k: string]: unknown;
242
+ };
243
+ min_confidence: number;
244
+ escalate_if_irreversible_above: number | null;
245
+ } | null, {
246
+ sets: Record<string, {
247
+ effect: string | null;
248
+ approve_when: string[];
249
+ deny_when: string[];
250
+ escalate_when: string[];
251
+ min_confidence: number | null;
252
+ escalate_if_irreversible_above: number | null;
253
+ }> & {
254
+ [k: string]: {
255
+ effect: string | null;
256
+ approve_when: string[];
257
+ deny_when: string[];
258
+ escalate_when: string[];
259
+ min_confidence: number | null;
260
+ escalate_if_irreversible_above: number | null;
261
+ };
262
+ };
263
+ tools: Record<string, string> & {
264
+ [k: string]: string;
265
+ };
266
+ default: string | null;
267
+ context: Record<string, unknown> & {
268
+ [k: string]: unknown;
269
+ };
270
+ min_confidence: number;
271
+ escalate_if_irreversible_above: number | null;
272
+ } | null | undefined>>;
273
+ agent_id: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null, string | null | undefined>>;
274
+ }, z.core.$strip>;
275
+ export type AgentConfig = z.output<typeof AgentConfigSchema>;
276
+ export type AgentConfigInput = z.input<typeof AgentConfigSchema>;
277
+ export declare const messagePayload: z.ZodDefault<z.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
278
+ export declare const AgentMessageSchema: z.ZodObject<{
279
+ type: z.ZodString;
280
+ payload: z.ZodDefault<z.ZodCustom<Record<string, unknown>, Record<string, unknown>>>;
281
+ }, z.core.$strip>;
282
+ export type AgentMessage = z.output<typeof AgentMessageSchema>;
283
+ export declare const TextMessage: z.ZodObject<{
284
+ text: z.ZodString;
285
+ }, z.core.$strip>;
286
+ export declare const TextReply: z.ZodObject<{
287
+ text: z.ZodString;
288
+ }, z.core.$strip>;
289
+ export interface MessageContext {
290
+ joined_turn: boolean;
291
+ turn_id: string;
292
+ turn_number: number;
293
+ message_id: string;
294
+ }
295
+ export interface AgentMessageReply {
296
+ turn_number: number;
297
+ turn_id: string;
298
+ message_id: string;
299
+ disposition: MessageDisposition;
300
+ accepted_offset: number;
301
+ }
302
+ export declare const ToolApprovalDecisionSchema: z.ZodObject<{
303
+ tool_id: z.ZodString;
304
+ approved: z.ZodBoolean;
305
+ reason: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null, string | null | undefined>>;
306
+ remember: z.ZodDefault<z.ZodBoolean>;
307
+ }, z.core.$strip>;
308
+ export type ToolApprovalDecision = z.output<typeof ToolApprovalDecisionSchema>;
309
+ export interface ToolApprovalResult {
310
+ tool_id: string;
311
+ accepted: boolean;
312
+ }
313
+ export declare const CallbackResultSchema: z.ZodObject<{
314
+ tool_id: z.ZodString;
315
+ result: z.ZodDefault<z.ZodUnknown>;
316
+ error: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null, string | null | undefined>>;
317
+ }, z.core.$strip>;
318
+ export type CallbackResult = z.output<typeof CallbackResultSchema>;
319
+ export interface CallbackResultAck {
320
+ tool_id: string;
321
+ accepted: boolean;
322
+ }
323
+ /** `turn_id` guards against cancelling a turn that opened after the caller looked. */
324
+ export interface PendingApproval {
325
+ tool_id: string;
326
+ tool_name: string;
327
+ tool_input: Record<string, unknown>;
328
+ turn_number: number;
329
+ short_id: string;
330
+ }
331
+ export interface PendingCallback {
332
+ tool_id: string;
333
+ tool_name: string;
334
+ tool_input: Record<string, unknown>;
335
+ output_schema: Record<string, unknown>;
336
+ turn_number: number;
337
+ }
338
+ export interface PendingTurn {
339
+ turn_number: number;
340
+ turn_id: string;
341
+ message_id: string;
342
+ message: string;
343
+ }
344
+ export interface SubagentInfo {
345
+ subagent_id: string;
346
+ agent_key: string;
347
+ workflow_id: string;
348
+ }
349
+ export interface AgentStatus {
350
+ agent_id: string;
351
+ current_turn: number;
352
+ turn_active: boolean;
353
+ turn_participants: number;
354
+ pending_turns: PendingTurn[];
355
+ pending_approvals: PendingApproval[];
356
+ pending_callbacks: PendingCallback[];
357
+ subagents: SubagentInfo[];
358
+ approval_policy: ToolApprovalPolicy;
359
+ has_auto_approval_evaluator: boolean;
360
+ }
361
+ /** One turn of the current run (a continued run keeps its last 20), as the `agent_state` query indexes it. */
362
+ export interface AcceptedFunction {
363
+ name: string;
364
+ description: string;
365
+ parameters: Record<string, unknown>;
366
+ output: Record<string, unknown>;
367
+ mid_turn: MidTurn;
368
+ model_callable: boolean;
369
+ }
@@ -0,0 +1,222 @@
1
+ // The agent's callable interface: the signal/update/query names an agent workflow and its clients
2
+ // share, the validated input models (zod, in place of pydantic), and the wire types (Python's
3
+ // agent_protocol/agent_interface.py). Every wire shape is snake_case JSON, identical to the Python
4
+ // harness, so the packaged UI, `@temporalio/agent-harness-client` and the Go connectors work against
5
+ // either backend. Workflow-sandbox safe (zod only).
6
+ import { z } from "zod";
7
+ export const SEND_AGENT_MESSAGE_UPDATE = "send_agent_message";
8
+ export const TOOL_APPROVAL_UPDATE = "tool_approval";
9
+ export const PROVIDE_CALLBACK_RESULT_UPDATE = "provide_callback_result";
10
+ export const AGENT_STATUS_QUERY = "agent_status";
11
+ export const AGENT_INTERFACE_QUERY = "agent_interface";
12
+ export const CLOSE_SIGNAL = "close";
13
+ export const AGENT_ID_LENGTH = 6;
14
+ export const APPROVAL_SHORT_ID_LENGTH = 6;
15
+ export const MidTurn = { ENQUEUE: "enqueue", REJECT: "reject", ACCEPT: "accept" };
16
+ export const MessageDisposition = { OPENED: "opened", JOINED: "joined", QUEUED: "queued" };
17
+ /** What an auto-mode evaluator decides, named after AI SDK 7's tool-approval outcomes. */
18
+ export const ApprovalVerdict = {
19
+ APPROVED: "approved",
20
+ DENIED: "denied",
21
+ USER_APPROVAL: "user-approval",
22
+ NOT_APPLICABLE: "not-applicable",
23
+ };
24
+ /** The verdict as it goes on the wire (auto_approval_evaluation_* events), as in Python. */
25
+ export const AutoApprovalVerdict = {
26
+ APPROVE: "approve",
27
+ DENY: "deny",
28
+ ESCALATE: "escalate",
29
+ };
30
+ /** Both of the evaluator's "not mine to decide" outcomes leave the call to a human. */
31
+ export const WIRE_VERDICT = {
32
+ approved: "approve",
33
+ denied: "deny",
34
+ "user-approval": "escalate",
35
+ "not-applicable": "escalate",
36
+ };
37
+ const AGENT_ID_PATTERN = new RegExp(`^[0-9a-f]{${AGENT_ID_LENGTH}}(-[0-9a-f]{${AGENT_ID_LENGTH}})*$`);
38
+ // The values pydantic's lax mode coerces, so a config Python accepts parses here too.
39
+ const TRUE_STRINGS = new Set(["true", "1", "yes", "on", "t", "y"]);
40
+ const FALSE_STRINGS = new Set(["false", "0", "no", "off", "f", "n"]);
41
+ const laxBool = z
42
+ .union([
43
+ z.boolean(),
44
+ z.literal([0, 1]),
45
+ z
46
+ .string()
47
+ .refine((s) => TRUE_STRINGS.has(s.toLowerCase()) || FALSE_STRINGS.has(s.toLowerCase()), {
48
+ message: "Input should be a valid boolean, unable to interpret input",
49
+ }),
50
+ ])
51
+ .transform((v) => typeof v === "string" ? TRUE_STRINGS.has(v.toLowerCase()) : typeof v === "number" ? v === 1 : v);
52
+ // Python float() syntax for a finite decimal, digits optionally grouped by single underscores.
53
+ const DIGITS = String.raw `\d(?:_?\d)*`;
54
+ const NUMERIC_STRING = new RegExp(String.raw `^\s*[+-]?(?:${DIGITS}(?:\.(?:${DIGITS})?)?|\.${DIGITS})(?:[eE][+-]?${DIGITS})?\s*$`);
55
+ const unit = z
56
+ .union([
57
+ z.number(),
58
+ z.boolean(),
59
+ z
60
+ .string()
61
+ .regex(NUMERIC_STRING, "Input should be a valid number, unable to parse string as a number"),
62
+ ])
63
+ .transform((v) => Number(typeof v === "string" ? v.replaceAll("_", "") : v))
64
+ .pipe(z.number().min(0).max(1));
65
+ // ---------------------------------------------------------------------------------------------
66
+ // Tool-approval policy. A plain, serializable value; derive the next one with the functions on
67
+ // `ToolApprovalPolicy`, which re-validate (the cross-field invariant included).
68
+ // ---------------------------------------------------------------------------------------------
69
+ export const ToolApprovalPolicySchema = z
70
+ .strictObject({
71
+ dangerously_skip_all_approvals: laxBool.default(false),
72
+ auto_approve_inherently_safe: laxBool.default(false),
73
+ auto_approve_tools: z
74
+ .array(z.string())
75
+ .default([])
76
+ .transform((tools) => [...new Set(tools)].sort()),
77
+ auto_mode_enabled: laxBool.default(false),
78
+ })
79
+ .refine((p) => !(p.dangerously_skip_all_approvals && p.auto_mode_enabled), {
80
+ message: "dangerously_skip_all_approvals=True approves every call outright, so no call is ever gated and " +
81
+ "auto mode could never be consulted. Set one or the other: skip approvals entirely, or enable " +
82
+ "auto mode over a policy that actually gates.",
83
+ });
84
+ export const ToolApprovalPolicy = {
85
+ parse: (value) => ToolApprovalPolicySchema.parse(value),
86
+ alwaysRequireHumanApproval: () => ToolApprovalPolicySchema.parse({}),
87
+ allowInherentlySafe: () => ToolApprovalPolicySchema.parse({ auto_approve_inherently_safe: true }),
88
+ allowTools: (tools, { alsoInherentlySafe = false } = {}) => ToolApprovalPolicySchema.parse({
89
+ auto_approve_tools: [...tools],
90
+ auto_approve_inherently_safe: alsoInherentlySafe,
91
+ }),
92
+ autoMode: ({ preApprovedTools = [], preApproveInherentlySafe = false, } = {}) => ToolApprovalPolicySchema.parse({
93
+ auto_approve_tools: [...preApprovedTools],
94
+ auto_approve_inherently_safe: preApproveInherentlySafe,
95
+ auto_mode_enabled: true,
96
+ }),
97
+ dangerouslySkipAll: () => ToolApprovalPolicySchema.parse({ dangerously_skip_all_approvals: true }),
98
+ withChanges: (policy, changes) => ToolApprovalPolicySchema.parse({ ...policy, ...changes }),
99
+ withToolAllowed: (policy, toolName) => ToolApprovalPolicySchema.parse({
100
+ ...policy,
101
+ auto_approve_tools: [...policy.auto_approve_tools, toolName],
102
+ }),
103
+ withAutoMode: (policy, enabled) => ToolApprovalPolicySchema.parse({ ...policy, auto_mode_enabled: enabled }),
104
+ /** Layers 0-2: dispatch with no gate and no approval events at all. */
105
+ autoApproves(policy, toolName, { inherentlySafe }) {
106
+ if (policy.dangerously_skip_all_approvals)
107
+ return true;
108
+ if (inherentlySafe && policy.auto_approve_inherently_safe)
109
+ return true;
110
+ return policy.auto_approve_tools.includes(toolName);
111
+ },
112
+ /** Layer 3: whether a call the static layers did not approve goes to the auto mode evaluator. */
113
+ consultsAutoMode(policy, toolName, opts) {
114
+ return !ToolApprovalPolicy.autoApproves(policy, toolName, opts) && policy.auto_mode_enabled;
115
+ },
116
+ };
117
+ // ---------------------------------------------------------------------------------------------
118
+ // Auto-approval criteria: the named rule sets an auto mode evaluator judges gated calls against.
119
+ // ---------------------------------------------------------------------------------------------
120
+ export const AutoApprovalCriteriaSetSchema = z.object({
121
+ effect: z.string().nullable().default(null),
122
+ approve_when: z.array(z.string()).default([]),
123
+ deny_when: z.array(z.string()).default([]),
124
+ escalate_when: z.array(z.string()).default([]),
125
+ min_confidence: unit.nullable().default(null),
126
+ escalate_if_irreversible_above: unit.nullable().default(null),
127
+ });
128
+ // z.record assigns into a plain object, where a "__proto__" key sets the prototype and vanishes.
129
+ const ownRecord = (value) => z
130
+ .preprocess((v, ctx) => {
131
+ if (typeof v === "object" && v !== null && !Array.isArray(v))
132
+ return new Map(Object.entries(v));
133
+ ctx.addIssue({ code: "invalid_type", expected: "record", input: v });
134
+ return z.NEVER;
135
+ }, z.map(z.string(), value))
136
+ .transform((m) => Object.assign(Object.create(null), Object.fromEntries(m)))
137
+ .prefault({});
138
+ export const AutoApprovalCriteriaSchema = z.object({
139
+ sets: ownRecord(AutoApprovalCriteriaSetSchema),
140
+ tools: ownRecord(z.string()),
141
+ default: z.string().nullable().default(null),
142
+ context: ownRecord(z.unknown()),
143
+ min_confidence: unit.default(0.8),
144
+ escalate_if_irreversible_above: unit.nullable().default(0.5),
145
+ });
146
+ const own = (record, key) => Object.hasOwn(record, key) ? record[key] : undefined;
147
+ export const AutoApprovalCriteria = {
148
+ parse: (value) => AutoApprovalCriteriaSchema.parse(value),
149
+ empty: () => AutoApprovalCriteriaSchema.parse({}),
150
+ criteriaSet: (value) => AutoApprovalCriteriaSetSchema.parse(value),
151
+ isEmptySet: (s) => !(s.effect || s.approve_when.length || s.deny_when.length || s.escalate_when.length),
152
+ /** Precedence: runtime/config assignment, then the tool's declared set, then the catch-all. */
153
+ setNameFor: (c, toolName, declared) => own(c.tools, toolName) || declared || c.default,
154
+ /** The set judging `toolName`, or null when there is nothing to judge against (escalate). */
155
+ forTool(c, toolName, declared) {
156
+ const name = AutoApprovalCriteria.setNameFor(c, toolName, declared);
157
+ const found = name === null ? undefined : own(c.sets, name);
158
+ return found === undefined || AutoApprovalCriteria.isEmptySet(found) ? null : found;
159
+ },
160
+ thresholdsForSet(c, s) {
161
+ if (s === null)
162
+ return [c.min_confidence, c.escalate_if_irreversible_above];
163
+ return [
164
+ s.min_confidence ?? c.min_confidence,
165
+ s.escalate_if_irreversible_above ?? c.escalate_if_irreversible_above,
166
+ ];
167
+ },
168
+ withSet: (c, name, s) => ({
169
+ ...c,
170
+ sets: Object.assign(Object.create(null), c.sets, { [name]: s }),
171
+ }),
172
+ withToolAssigned: (c, toolName, setName) => ({
173
+ ...c,
174
+ tools: Object.assign(Object.create(null), c.tools, { [toolName]: setName }),
175
+ }),
176
+ };
177
+ // ---------------------------------------------------------------------------------------------
178
+ // Standardized agent input and messages
179
+ // ---------------------------------------------------------------------------------------------
180
+ export const AgentConfigSchema = z.object({
181
+ approval_policy: ToolApprovalPolicySchema.nullish().transform((v) => v ?? null),
182
+ auto_approval_criteria: AutoApprovalCriteriaSchema.nullish().transform((v) => v ?? null),
183
+ agent_id: z
184
+ .string()
185
+ .regex(AGENT_ID_PATTERN)
186
+ .nullish()
187
+ .transform((v) => v ?? null),
188
+ });
189
+ // Not z.record, which rebuilds the object and drops a "__proto__" key.
190
+ export const messagePayload = z
191
+ .custom((v) => typeof v === "object" && v !== null && !Array.isArray(v), "Expected an object")
192
+ .default({});
193
+ export const AgentMessageSchema = z.object({
194
+ type: z.string(),
195
+ payload: messagePayload,
196
+ });
197
+ // Schemas as Python's pydantic models publish them (field titles included), for wire parity.
198
+ export const TextMessage = z.object({ text: z.string().meta({ title: "Text" }) }).meta({
199
+ title: "TextMessage",
200
+ description: "Free-form natural-language text from the user (the input to a plain chat handler).",
201
+ });
202
+ export const TextReply = z.object({ text: z.string().meta({ title: "Text" }) }).meta({
203
+ title: "TextReply",
204
+ description: "A free-form natural-language reply (the output of a plain chat handler).",
205
+ });
206
+ export const ToolApprovalDecisionSchema = z.object({
207
+ tool_id: z.string(),
208
+ approved: z.boolean(),
209
+ reason: z
210
+ .string()
211
+ .nullish()
212
+ .transform((v) => v ?? null),
213
+ remember: z.boolean().default(false),
214
+ });
215
+ export const CallbackResultSchema = z.object({
216
+ tool_id: z.string(),
217
+ result: z.unknown().default(null),
218
+ error: z
219
+ .string()
220
+ .nullish()
221
+ .transform((v) => v ?? null),
222
+ });
@@ -0,0 +1,10 @@
1
+ import type { Protocol } from "@temporalio/agent-harness-client";
2
+ export type AgentEvent = Protocol.AgentEvent;
3
+ export type AgentStreamItem = Protocol.AgentStreamItem;
4
+ export type AgentEventType = Protocol.AgentEventType;
5
+ export type TokenUsage = Protocol.TokenUsage;
6
+ export type JsonValue = Protocol.JsonValue;
7
+ export type StreamEventOf<T extends AgentEventType> = Extract<AgentStreamItem, {
8
+ type: T;
9
+ }>;
10
+ export declare const TURN_EVENTS_TOPIC = "turn_events";
@@ -0,0 +1,6 @@
1
+ // The agent's event-stream vocabulary (Python's agent_protocol/events.py). The event types are not
2
+ // redeclared here: they are the generated `Protocol` namespace of `@temporalio/agent-harness-client`,
3
+ // itself generated from contract/protocol.schema.json, so a payload this backend publishes is
4
+ // type-checked against exactly what the client and UI parse.
5
+ // The pubsub topic the agent publishes its turn events on.
6
+ export const TURN_EVENTS_TOPIC = "turn_events";
@@ -0,0 +1,5 @@
1
+ export * from "./events.ts";
2
+ export * from "./agent-interface.ts";
3
+ export * from "./subagent-interface.ts";
4
+ export * from "./schema.ts";
5
+ export { TurnStreamContextSchema, type TurnStreamContext } from "../stream-context.ts";
@@ -0,0 +1,7 @@
1
+ // The agent protocol (Python's agent_protocol package): the event vocabulary, the agent's callable
2
+ // interface, and the subagent-turn contract.
3
+ export * from "./events.js";
4
+ export * from "./agent-interface.js";
5
+ export * from "./subagent-interface.js";
6
+ export * from "./schema.js";
7
+ export { TurnStreamContextSchema } from "../stream-context.js";
@@ -0,0 +1,34 @@
1
+ import type { StandardJSONSchemaV1, StandardSchemaV1, StandardTypedV1 } from "@standard-schema/spec";
2
+ /** Standard Schema (`~standard.validate`) plus Standard JSON Schema (`~standard.jsonSchema`). */
3
+ export interface Schema<I = unknown, O = I> {
4
+ readonly "~standard": StandardSchemaV1.Props<I, O> & StandardJSONSchemaV1.Props<I, O>;
5
+ }
6
+ export type InferInput<S extends Schema> = StandardTypedV1.InferInput<S>;
7
+ export type InferOutput<S extends Schema> = StandardTypedV1.InferOutput<S>;
8
+ /**
9
+ * JSON Schema of a schema: what it accepts (`input`, the default) or what parsing returns (`output`).
10
+ * zod renders each mode as it behaves: an input object is open, since parsing ignores extra keys,
11
+ * and an output object is closed.
12
+ */
13
+ export declare function toJsonSchema(schema: Schema, io?: "input" | "output"): Record<string, unknown>;
14
+ /** Validate synchronously; schemas with async refinements are rejected. */
15
+ export declare function validate<S extends Schema>(schema: S, value: unknown): {
16
+ ok: true;
17
+ value: InferOutput<S>;
18
+ } | {
19
+ ok: false;
20
+ message: string;
21
+ };
22
+ /**
23
+ * Raw JSON Schema as a harness schema (the AI SDK's `jsonSchema()` counterpart). Values pass
24
+ * unchecked unless `validate` is given, so prefer a schema library where input is untrusted.
25
+ */
26
+ export declare function jsonSchema<T = unknown>(schema: Record<string, unknown>, options?: {
27
+ validate?: (value: unknown) => {
28
+ ok: true;
29
+ value: T;
30
+ } | {
31
+ ok: false;
32
+ message: string;
33
+ };
34
+ }): Schema<T>;