@ai-sdk/harness 0.0.0 → 1.0.0-beta.14

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 (67) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/LICENSE +13 -0
  3. package/README.md +142 -0
  4. package/agent/index.ts +47 -0
  5. package/bridge/index.ts +10 -0
  6. package/dist/agent/index.d.ts +1521 -0
  7. package/dist/agent/index.js +2958 -0
  8. package/dist/agent/index.js.map +1 -0
  9. package/dist/bridge/index.d.ts +111 -0
  10. package/dist/bridge/index.js +415 -0
  11. package/dist/bridge/index.js.map +1 -0
  12. package/dist/index.d.ts +1536 -0
  13. package/dist/index.js +15834 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/utils/index.d.ts +225 -0
  16. package/dist/utils/index.js +12148 -0
  17. package/dist/utils/index.js.map +1 -0
  18. package/package.json +99 -1
  19. package/src/agent/harness-agent-session.ts +509 -0
  20. package/src/agent/harness-agent-settings.ts +131 -0
  21. package/src/agent/harness-agent-tool-approval-continuation.ts +94 -0
  22. package/src/agent/harness-agent-types.ts +50 -0
  23. package/src/agent/harness-agent.ts +819 -0
  24. package/src/agent/internal/bootstrap-recipe.ts +124 -0
  25. package/src/agent/internal/bridge-port-registry.ts +52 -0
  26. package/src/agent/internal/harness-stream-text-result.ts +720 -0
  27. package/src/agent/internal/lifecycle-state-validation.ts +95 -0
  28. package/src/agent/internal/permission-mode.ts +50 -0
  29. package/src/agent/internal/resolve-observability.ts +128 -0
  30. package/src/agent/internal/run-prompt.ts +813 -0
  31. package/src/agent/internal/strip-work-dir.ts +68 -0
  32. package/src/agent/internal/to-harness-stream.ts +75 -0
  33. package/src/agent/internal/translate-stream-part.ts +221 -0
  34. package/src/agent/internal/turn-telemetry.ts +359 -0
  35. package/src/agent/observability/file-reporter.ts +206 -0
  36. package/src/agent/observability/index.ts +15 -0
  37. package/src/agent/observability/trace-tree-reporter.ts +122 -0
  38. package/src/agent/observability/types.ts +86 -0
  39. package/src/agent/prewarm.ts +47 -0
  40. package/src/bridge/index.ts +702 -0
  41. package/src/errors/harness-capability-unsupported-error.ts +41 -0
  42. package/src/errors/harness-error.ts +22 -0
  43. package/src/index.ts +3 -0
  44. package/src/utils/bridge-ready.ts +277 -0
  45. package/src/utils/classify-disk-log.ts +43 -0
  46. package/src/utils/index.ts +15 -0
  47. package/src/utils/sandbox-channel.ts +453 -0
  48. package/src/v1/harness-v1-bootstrap.ts +46 -0
  49. package/src/v1/harness-v1-bridge-protocol.ts +310 -0
  50. package/src/v1/harness-v1-builtin-tool.ts +138 -0
  51. package/src/v1/harness-v1-call-warning.ts +22 -0
  52. package/src/v1/harness-v1-diagnostic.ts +66 -0
  53. package/src/v1/harness-v1-lifecycle-state.ts +65 -0
  54. package/src/v1/harness-v1-metadata.ts +13 -0
  55. package/src/v1/harness-v1-network-sandbox-session.ts +123 -0
  56. package/src/v1/harness-v1-observability.ts +20 -0
  57. package/src/v1/harness-v1-permission-mode.ts +11 -0
  58. package/src/v1/harness-v1-prompt-control.ts +41 -0
  59. package/src/v1/harness-v1-prompt.ts +11 -0
  60. package/src/v1/harness-v1-sandbox-provider.ts +76 -0
  61. package/src/v1/harness-v1-session.ts +272 -0
  62. package/src/v1/harness-v1-skill.ts +36 -0
  63. package/src/v1/harness-v1-stream-part.ts +363 -0
  64. package/src/v1/harness-v1-tool-spec.ts +31 -0
  65. package/src/v1/harness-v1.ts +83 -0
  66. package/src/v1/index.ts +93 -0
  67. package/utils/index.ts +1 -0
@@ -0,0 +1,86 @@
1
+ /*
2
+ * Host/consumer-facing observability types.
3
+ *
4
+ * These are deliberately NOT part of the versioned adapter spec: no harness
5
+ * adapter implements or consumes them. Adapters only deal with bridge wire
6
+ * frames and the observability handle the framework hands to `doStart`. The
7
+ * framework normalizes those frames into the `HarnessDiagnostic` shape below
8
+ * for consumers (`HarnessAgentSettings.onLog`) and reporters.
9
+ */
10
+
11
+ /** Severity of a diagnostic. */
12
+ export type HarnessDebugLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace';
13
+
14
+ /**
15
+ * Consumer-facing diagnostics configuration. Set on `HarnessAgentSettings` to
16
+ * enable bridge log forwarding and the `HARNESS_DEBUG` stderr default in code.
17
+ * `HARNESS_DEBUG` / `HARNESS_DEBUG_LEVEL` / `HARNESS_DEBUG_SUBSYSTEMS` env vars
18
+ * fill any unset field — a convenience default, never the only path.
19
+ */
20
+ export type HarnessDebugConfig = {
21
+ /** Master switch. Nothing is captured or forwarded when false/unset. */
22
+ readonly enabled?: boolean;
23
+ /** Threshold; events at or above this severity are emitted. Default `debug`. */
24
+ readonly level?: HarnessDebugLevel;
25
+ /** Dotted-prefix subsystem filter for structured events. */
26
+ readonly subsystems?: ReadonlyArray<string>;
27
+ };
28
+
29
+ /**
30
+ * A forwarded bridge diagnostic, normalized for host consumers.
31
+ *
32
+ * The bridge emits two raw frame kinds — captured console lines (`sandbox-log`)
33
+ * and structured events (`debug-event`). The framework normalizes both into
34
+ * this single shape before handing them to a consumer's `onLog` callback, the
35
+ * `HARNESS_DEBUG` stderr default, and observability reporters. Diagnostics are
36
+ * kept first-class and per-line — they are never folded into telemetry spans.
37
+ */
38
+ export type HarnessDiagnostic = {
39
+ /**
40
+ * Severity. Structured events carry their own level; captured console lines
41
+ * map `stderr` → `'warn'` and `stdout` → `'info'`.
42
+ */
43
+ readonly level: HarnessDebugLevel;
44
+
45
+ /** Human-readable line (console capture) or message (structured event). */
46
+ readonly message: string;
47
+
48
+ /**
49
+ * Dotted subsystem. For captured console output this is
50
+ * `sandbox.log.<source>`; for structured events it is the adapter-supplied
51
+ * subsystem (e.g. `bridge.turn`).
52
+ */
53
+ readonly subsystem: string;
54
+
55
+ /** `'log'` = captured console line; `'event'` = structured `bridgeLog`. */
56
+ readonly kind: 'log' | 'event';
57
+
58
+ /** Originating sandbox source label (console capture). */
59
+ readonly source?: string;
60
+
61
+ /** Which standard stream the line came from (console capture). */
62
+ readonly stream?: 'stdout' | 'stderr';
63
+
64
+ /** Structured attributes (structured events only). */
65
+ readonly attrs?: Record<string, unknown>;
66
+
67
+ /** Error payload (structured events only). */
68
+ readonly error?: { name?: string; message: string; stack?: string };
69
+
70
+ /** The harness session this diagnostic originated from. */
71
+ readonly sessionId?: string;
72
+
73
+ /** Host receipt time (epoch ms). */
74
+ readonly timestamp: number;
75
+ };
76
+
77
+ /**
78
+ * A telemetry integration that also wants the per-line diagnostics stream. The
79
+ * framework calls `ingestDiagnostic` for every forwarded bridge diagnostic in
80
+ * addition to driving the standard `Telemetry` span lifecycle, so a single
81
+ * reporter object (e.g. `createFileReporter`) registered in
82
+ * `telemetry.integrations` receives both spans and logs.
83
+ */
84
+ export interface HarnessDiagnosticConsumer {
85
+ ingestDiagnostic?(diagnostic: HarnessDiagnostic): void;
86
+ }
@@ -0,0 +1,47 @@
1
+ import type { HarnessV1SandboxProvider } from '../v1';
2
+ import type { HarnessAgentAdapter } from './harness-agent-types';
3
+ import {
4
+ applyBootstrapRecipe,
5
+ hashBootstrap,
6
+ } from './internal/bootstrap-recipe';
7
+
8
+ /**
9
+ * Pre-build a harness's sandbox template without running an agent. Idempotent:
10
+ * if the template already exists (snapshot present, or marker on a non-snapshot
11
+ * provider), this resolves quickly.
12
+ *
13
+ * Use from a CI/deploy script to amortize the first-session cost so production
14
+ * sessions always resume from snapshot. For adapters without a bootstrap
15
+ * recipe (no `getBootstrap`) this is a no-op.
16
+ *
17
+ * The temporary network sandbox session created during pre-warm is stopped
18
+ * before the function resolves; the snapshot/template state persists in the
19
+ * provider's native storage (for Vercel: as the `currentSnapshotId` of the
20
+ * named template sandbox).
21
+ */
22
+ export async function prewarmHarness(options: {
23
+ readonly harness: HarnessAgentAdapter;
24
+ readonly sandboxProvider: HarnessV1SandboxProvider;
25
+ readonly abortSignal?: AbortSignal;
26
+ }): Promise<void> {
27
+ const recipe = await options.harness.getBootstrap?.({
28
+ abortSignal: options.abortSignal,
29
+ });
30
+ if (recipe == null) return;
31
+
32
+ const identity = await hashBootstrap(recipe);
33
+ const sandboxSession = await options.sandboxProvider.createSession({
34
+ abortSignal: options.abortSignal,
35
+ identity,
36
+ onFirstCreate: (session, opts) =>
37
+ applyBootstrapRecipe(session, recipe, identity, opts),
38
+ });
39
+
40
+ try {
41
+ await applyBootstrapRecipe(sandboxSession.restricted(), recipe, identity, {
42
+ abortSignal: options.abortSignal,
43
+ });
44
+ } finally {
45
+ await Promise.resolve(sandboxSession.stop()).catch(() => {});
46
+ }
47
+ }