@ai-sdk/harness 0.0.0-6b196531-20260710185421

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 (77) hide show
  1. package/CHANGELOG.md +414 -0
  2. package/LICENSE +13 -0
  3. package/README.md +176 -0
  4. package/agent/index.ts +56 -0
  5. package/bridge/index.ts +10 -0
  6. package/dist/agent/index.d.ts +1631 -0
  7. package/dist/agent/index.js +3491 -0
  8. package/dist/agent/index.js.map +1 -0
  9. package/dist/bridge/index.d.ts +129 -0
  10. package/dist/bridge/index.js +482 -0
  11. package/dist/bridge/index.js.map +1 -0
  12. package/dist/index.d.ts +1587 -0
  13. package/dist/index.js +517 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/utils/index.d.ts +329 -0
  16. package/dist/utils/index.js +1241 -0
  17. package/dist/utils/index.js.map +1 -0
  18. package/package.json +100 -0
  19. package/src/agent/harness-agent-session.ts +518 -0
  20. package/src/agent/harness-agent-settings.ts +187 -0
  21. package/src/agent/harness-agent-tool-approval-continuation.ts +94 -0
  22. package/src/agent/harness-agent-tool-types.ts +15 -0
  23. package/src/agent/harness-agent-types.ts +50 -0
  24. package/src/agent/harness-agent.ts +865 -0
  25. package/src/agent/internal/bootstrap-recipe.ts +124 -0
  26. package/src/agent/internal/bridge-port-registry.ts +52 -0
  27. package/src/agent/internal/harness-stream-text-result.ts +731 -0
  28. package/src/agent/internal/lifecycle-state-validation.ts +95 -0
  29. package/src/agent/internal/permission-mode.ts +50 -0
  30. package/src/agent/internal/resolve-observability.ts +128 -0
  31. package/src/agent/internal/run-prompt.ts +901 -0
  32. package/src/agent/internal/sandbox-bootstrap.ts +266 -0
  33. package/src/agent/internal/strip-work-dir.ts +68 -0
  34. package/src/agent/internal/to-harness-stream.ts +75 -0
  35. package/src/agent/internal/tool-filtering.ts +114 -0
  36. package/src/agent/internal/translate-stream-part.ts +221 -0
  37. package/src/agent/internal/turn-telemetry.ts +361 -0
  38. package/src/agent/observability/file-reporter.ts +206 -0
  39. package/src/agent/observability/index.ts +15 -0
  40. package/src/agent/observability/trace-tree-reporter.ts +122 -0
  41. package/src/agent/observability/types.ts +86 -0
  42. package/src/agent/prepare-harness-sandbox-template.ts +68 -0
  43. package/src/agent/prepare-sandbox-for-harness.ts +165 -0
  44. package/src/bridge/index.ts +797 -0
  45. package/src/errors/harness-capability-unsupported-error.ts +41 -0
  46. package/src/errors/harness-error.ts +22 -0
  47. package/src/index.ts +3 -0
  48. package/src/utils/ai-gateway-auth.ts +15 -0
  49. package/src/utils/bridge-diagnostics.ts +213 -0
  50. package/src/utils/bridge-ready.ts +277 -0
  51. package/src/utils/classify-disk-log.ts +43 -0
  52. package/src/utils/index.ts +31 -0
  53. package/src/utils/sandbox-channel.ts +525 -0
  54. package/src/utils/sandbox-home-dir.ts +22 -0
  55. package/src/utils/shell-quote.ts +3 -0
  56. package/src/utils/write-skills.ts +141 -0
  57. package/src/v1/harness-v1-bootstrap.ts +46 -0
  58. package/src/v1/harness-v1-bridge-protocol.ts +342 -0
  59. package/src/v1/harness-v1-builtin-tool.ts +138 -0
  60. package/src/v1/harness-v1-call-warning.ts +22 -0
  61. package/src/v1/harness-v1-diagnostic.ts +66 -0
  62. package/src/v1/harness-v1-lifecycle-state.ts +65 -0
  63. package/src/v1/harness-v1-metadata.ts +13 -0
  64. package/src/v1/harness-v1-network-sandbox-session.ts +123 -0
  65. package/src/v1/harness-v1-observability.ts +20 -0
  66. package/src/v1/harness-v1-permission-mode.ts +11 -0
  67. package/src/v1/harness-v1-prompt-control.ts +41 -0
  68. package/src/v1/harness-v1-prompt.ts +11 -0
  69. package/src/v1/harness-v1-sandbox-provider.ts +76 -0
  70. package/src/v1/harness-v1-session.ts +280 -0
  71. package/src/v1/harness-v1-skill.ts +36 -0
  72. package/src/v1/harness-v1-stream-part.ts +363 -0
  73. package/src/v1/harness-v1-tool-filtering.ts +25 -0
  74. package/src/v1/harness-v1-tool-spec.ts +31 -0
  75. package/src/v1/harness-v1.ts +94 -0
  76. package/src/v1/index.ts +99 -0
  77. package/utils/index.ts +1 -0
@@ -0,0 +1,94 @@
1
+ import { HarnessError } from '../errors/harness-error';
2
+ import type {
3
+ ModelMessage,
4
+ ToolApprovalRequest,
5
+ ToolApprovalResponse,
6
+ } from '@ai-sdk/provider-utils';
7
+
8
+ export type HarnessAgentToolApprovalContinuation = {
9
+ readonly approvalResponse: ToolApprovalResponse;
10
+ readonly toolCall: {
11
+ readonly type: 'tool-call';
12
+ readonly toolCallId: string;
13
+ readonly toolName: string;
14
+ readonly input: unknown;
15
+ readonly providerExecuted?: boolean;
16
+ };
17
+ };
18
+
19
+ /**
20
+ * Extract approval decisions that should continue a suspended harness turn.
21
+ *
22
+ * AI SDK clients send approval decisions as a trailing `role: "tool"` message
23
+ * containing `tool-approval-response` parts. The response only carries the
24
+ * approval id, so the harness has to recover the matching approval request
25
+ * locally to find the original tool call before it can resume the paused turn.
26
+ * Responses that already have a tool result are ignored, because those
27
+ * approvals were already consumed by a prior continuation.
28
+ */
29
+ export function collectHarnessAgentToolApprovalContinuations(input: {
30
+ messages: readonly ModelMessage[];
31
+ }): readonly HarnessAgentToolApprovalContinuation[] {
32
+ const lastMessage = input.messages.at(-1);
33
+ if (lastMessage?.role !== 'tool') return [];
34
+
35
+ const toolCallsByToolCallId = new Map<
36
+ string,
37
+ HarnessAgentToolApprovalContinuation['toolCall']
38
+ >();
39
+ const approvalRequestsByApprovalId = new Map<string, ToolApprovalRequest>();
40
+ for (const message of input.messages) {
41
+ if (message.role !== 'assistant' || typeof message.content === 'string') {
42
+ continue;
43
+ }
44
+ for (const part of message.content) {
45
+ if (part.type === 'tool-call') {
46
+ toolCallsByToolCallId.set(part.toolCallId, {
47
+ type: 'tool-call',
48
+ toolCallId: part.toolCallId,
49
+ toolName: part.toolName,
50
+ input: part.input,
51
+ ...(part.providerExecuted !== undefined
52
+ ? { providerExecuted: part.providerExecuted }
53
+ : {}),
54
+ });
55
+ } else if (part.type === 'tool-approval-request') {
56
+ approvalRequestsByApprovalId.set(part.approvalId, part);
57
+ }
58
+ }
59
+ }
60
+
61
+ const toolResultIds = new Set<string>();
62
+ for (const part of lastMessage.content) {
63
+ if (part.type === 'tool-result') {
64
+ toolResultIds.add(part.toolCallId);
65
+ }
66
+ }
67
+
68
+ const continuations: HarnessAgentToolApprovalContinuation[] = [];
69
+ for (const part of lastMessage.content) {
70
+ if (part.type !== 'tool-approval-response') continue;
71
+
72
+ const approvalRequest = approvalRequestsByApprovalId.get(part.approvalId);
73
+ if (approvalRequest == null) {
74
+ throw new HarnessError({
75
+ message: `Tool approval response '${part.approvalId}' does not match a prior tool approval request.`,
76
+ });
77
+ }
78
+ if (toolResultIds.has(approvalRequest.toolCallId)) continue;
79
+
80
+ const toolCall = toolCallsByToolCallId.get(approvalRequest.toolCallId);
81
+ if (toolCall == null) {
82
+ throw new HarnessError({
83
+ message: `Tool approval request '${approvalRequest.approvalId}' references unknown tool call '${approvalRequest.toolCallId}'.`,
84
+ });
85
+ }
86
+
87
+ continuations.push({
88
+ approvalResponse: part,
89
+ toolCall,
90
+ });
91
+ }
92
+
93
+ return continuations;
94
+ }
@@ -0,0 +1,15 @@
1
+ import type { HarnessAgentAdapter } from './harness-agent-types';
2
+ import type { ToolSet } from '@ai-sdk/provider-utils';
3
+
4
+ /** Extract the builtin tool set type from a harness adapter parameter. */
5
+ export type HarnessBuiltinToolsOf<H> =
6
+ H extends HarnessAgentAdapter<infer T> ? T : never;
7
+
8
+ /**
9
+ * Type-level merge of a harness's builtin tools with user-defined tools.
10
+ * User tools override builtins on key collision.
11
+ */
12
+ export type HarnessAllTools<
13
+ THarness extends HarnessAgentAdapter<any>,
14
+ TUserTools extends ToolSet,
15
+ > = Omit<HarnessBuiltinToolsOf<THarness>, keyof TUserTools> & TUserTools;
@@ -0,0 +1,50 @@
1
+ import type { ToolSet } from '@ai-sdk/provider-utils';
2
+ import type {
3
+ HARNESS_V1_BUILTIN_TOOLS,
4
+ HarnessV1,
5
+ HarnessV1BuiltinTool,
6
+ HarnessV1BuiltinToolName,
7
+ HarnessV1BuiltinToolUseKind,
8
+ HarnessV1ContinueTurnOptions,
9
+ HarnessV1ContinueTurnState,
10
+ HarnessV1LifecycleState,
11
+ HarnessV1PendingToolApproval,
12
+ HarnessV1PermissionMode,
13
+ HarnessV1Prompt,
14
+ HarnessV1PromptControl,
15
+ HarnessV1PromptTurnOptions,
16
+ HarnessV1ResumeSessionState,
17
+ HarnessV1Session,
18
+ HarnessV1Skill,
19
+ HarnessV1StartOptions,
20
+ HarnessV1StreamPart,
21
+ HarnessV1ToolSpec,
22
+ } from '../v1';
23
+
24
+ export type HarnessAgentAdapter<TBuiltinTools extends ToolSet = ToolSet> =
25
+ HarnessV1<TBuiltinTools>;
26
+
27
+ export type HarnessAgentBuiltinTool<
28
+ INPUT = unknown,
29
+ OUTPUT = unknown,
30
+ > = HarnessV1BuiltinTool<INPUT, OUTPUT>;
31
+ export type HarnessAgentBuiltinToolName = HarnessV1BuiltinToolName;
32
+ export type HarnessAgentBuiltinToolUseKind = HarnessV1BuiltinToolUseKind;
33
+ export type HarnessAgentBuiltinTools = typeof HARNESS_V1_BUILTIN_TOOLS;
34
+
35
+ export type HarnessAgentStartOptions = HarnessV1StartOptions;
36
+ export type HarnessAgentAdapterSession = HarnessV1Session;
37
+ export type HarnessAgentPrompt = HarnessV1Prompt;
38
+ export type HarnessAgentPromptControl = HarnessV1PromptControl;
39
+ export type HarnessAgentPromptTurnOptions = HarnessV1PromptTurnOptions;
40
+ export type HarnessAgentContinueTurnOptions = HarnessV1ContinueTurnOptions;
41
+ export type HarnessAgentStreamPart = HarnessV1StreamPart;
42
+ export type HarnessAgentToolSpec = HarnessV1ToolSpec;
43
+
44
+ export type HarnessAgentLifecycleState = HarnessV1LifecycleState;
45
+ export type HarnessAgentResumeSessionState = HarnessV1ResumeSessionState;
46
+ export type HarnessAgentContinueTurnState = HarnessV1ContinueTurnState;
47
+ export type HarnessAgentPendingToolApproval = HarnessV1PendingToolApproval;
48
+
49
+ export type HarnessAgentSkill = HarnessV1Skill;
50
+ export type HarnessAgentPermissionMode = HarnessV1PermissionMode;