@agent-compose/sdk 0.7.0 → 0.8.1

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 (119) hide show
  1. package/README.md +66 -39
  2. package/dist/agent/__tests__/runtime-json-schema.test.d.ts +10 -0
  3. package/dist/agent/agent-context.d.ts +21 -1
  4. package/dist/agent/agent-loop.d.ts +32 -1
  5. package/dist/agent/run-agent.d.ts +4 -0
  6. package/dist/client.d.ts +382 -534
  7. package/dist/directives.d.ts +112 -0
  8. package/dist/display.d.ts +258 -0
  9. package/dist/errors.d.ts +24 -1
  10. package/dist/index.d.ts +26 -14
  11. package/dist/index.js +3774 -1679
  12. package/dist/pause/wrappers.d.ts +31 -9
  13. package/dist/runtimes/_acp-client.d.ts +46 -1
  14. package/dist/runtimes/_cli-agent.d.ts +51 -4
  15. package/dist/runtimes/_jsonl-guard.d.ts +103 -0
  16. package/dist/runtimes/amp.d.ts +2 -2
  17. package/dist/runtimes/claude-code.d.ts +61 -0
  18. package/dist/runtimes/claude-code.test.d.ts +14 -0
  19. package/dist/runtimes/claude.d.ts +16 -0
  20. package/dist/runtimes/claude.test.d.ts +8 -0
  21. package/dist/runtimes/codex.d.ts +12 -3
  22. package/dist/runtimes/cursor.d.ts +2 -2
  23. package/dist/runtimes/droid.d.ts +2 -2
  24. package/dist/runtimes/jsonl-guard.test.d.ts +19 -0
  25. package/dist/runtimes/openai-desktop.js +3718 -1680
  26. package/dist/runtimes/opencode.d.ts +2 -2
  27. package/dist/runtimes/vercel.js +12 -1
  28. package/dist/sandbox/devbox.d.ts +42 -0
  29. package/dist/sandbox/exec-stream.d.ts +14 -0
  30. package/dist/sandbox/network-policy.d.ts +100 -0
  31. package/dist/sandbox/provider-def.d.ts +79 -0
  32. package/dist/sandbox/providers/desktop.d.ts +10 -0
  33. package/dist/sandbox/providers/e2b.d.ts +17 -0
  34. package/dist/sandbox/providers/local.d.ts +11 -0
  35. package/dist/sandbox/providers/vercel.d.ts +18 -0
  36. package/dist/sandbox/registry.d.ts +45 -0
  37. package/dist/sandbox/sizes.d.ts +68 -0
  38. package/dist/sandbox.d.ts +24 -299
  39. package/dist/step-invocation/__tests__/foreground-recovery.test.d.ts +1 -0
  40. package/dist/step-invocation/invoker.d.ts +10 -0
  41. package/dist/step-invocation/protocol.d.ts +5 -0
  42. package/dist/types/api-compliance.d.ts +71 -0
  43. package/dist/types/api-conversations.d.ts +523 -0
  44. package/dist/types/api-factory.d.ts +334 -0
  45. package/dist/types/api-projects.d.ts +131 -0
  46. package/dist/types/api-runs.d.ts +422 -0
  47. package/dist/types/api-scopes.d.ts +102 -0
  48. package/dist/types/conversation-stream.d.ts +191 -0
  49. package/dist/types/execution-context.d.ts +12 -2
  50. package/dist/types/protocol.d.ts +38 -1
  51. package/dist/types/sandbox-environment.d.ts +8 -5
  52. package/dist/types/sandbox.d.ts +74 -4
  53. package/dist/types/workflow-metadata.d.ts +41 -8
  54. package/dist/types/workflow-plan.d.ts +10 -0
  55. package/dist/types/workflow.d.ts +18 -205
  56. package/dist/utils/bundler.d.ts +68 -1
  57. package/dist/workflow-steps/index.d.ts +1 -1
  58. package/dist/workflow-steps/observability.d.ts +8 -1
  59. package/dist/workflow-steps/runner.d.ts +3 -3
  60. package/dist/workflow-steps/step.d.ts +15 -1
  61. package/dist/workflow-steps/types.d.ts +19 -5
  62. package/dist/workflow-steps/workflow.d.ts +29 -1
  63. package/dist/workflows/engine.d.ts +3 -2
  64. package/dist/workflows/invoke-child.d.ts +20 -2
  65. package/dist/workflows/invoke-child.test.d.ts +9 -0
  66. package/package.json +2 -2
  67. package/src/agent/agent-context.ts +186 -3
  68. package/src/agent/agent-loop.ts +40 -2
  69. package/src/agent/run-agent.ts +5 -0
  70. package/src/client.ts +1048 -625
  71. package/src/directives.ts +184 -0
  72. package/src/display.ts +834 -0
  73. package/src/errors.ts +39 -0
  74. package/src/index.ts +114 -12
  75. package/src/pause/wrappers.ts +44 -9
  76. package/src/runtimes/_acp-client.ts +72 -3
  77. package/src/runtimes/_cli-agent.ts +161 -36
  78. package/src/runtimes/_jsonl-guard.ts +219 -0
  79. package/src/runtimes/claude-code.ts +256 -0
  80. package/src/runtimes/claude.ts +32 -2
  81. package/src/runtimes/codex.ts +63 -3
  82. package/src/runtimes/openai-desktop.ts +59 -14
  83. package/src/sandbox/devbox.ts +48 -0
  84. package/src/sandbox/exec-stream.ts +48 -0
  85. package/src/sandbox/network-policy.ts +181 -0
  86. package/src/sandbox/provider-def.ts +94 -0
  87. package/src/sandbox/providers/desktop.ts +57 -0
  88. package/src/sandbox/providers/e2b.ts +354 -0
  89. package/src/sandbox/providers/local.ts +106 -0
  90. package/src/sandbox/providers/vercel.ts +331 -0
  91. package/src/sandbox/registry.ts +198 -0
  92. package/src/sandbox/sizes.ts +95 -0
  93. package/src/sandbox.ts +59 -1275
  94. package/src/step-invocation/invoker.ts +151 -28
  95. package/src/step-invocation/protocol.ts +8 -0
  96. package/src/types/api-compliance.ts +79 -0
  97. package/src/types/api-conversations.ts +547 -0
  98. package/src/types/api-factory.ts +368 -0
  99. package/src/types/api-projects.ts +140 -0
  100. package/src/types/api-runs.ts +459 -0
  101. package/src/types/api-scopes.ts +102 -0
  102. package/src/types/conversation-stream.ts +231 -0
  103. package/src/types/execution-context.ts +10 -2
  104. package/src/types/protocol.ts +41 -0
  105. package/src/types/sandbox-environment.ts +28 -9
  106. package/src/types/sandbox.ts +73 -4
  107. package/src/types/workflow-metadata.ts +44 -8
  108. package/src/types/workflow-plan.ts +11 -0
  109. package/src/types/workflow.ts +25 -292
  110. package/src/utils/bundler.ts +245 -8
  111. package/src/utils/errors.ts +16 -1
  112. package/src/workflow-steps/index.ts +1 -0
  113. package/src/workflow-steps/observability.ts +19 -8
  114. package/src/workflow-steps/runner.ts +4 -4
  115. package/src/workflow-steps/step.ts +49 -1
  116. package/src/workflow-steps/types.ts +20 -5
  117. package/src/workflow-steps/workflow.ts +29 -1
  118. package/src/workflows/engine.ts +3 -2
  119. package/src/workflows/invoke-child.ts +49 -13
@@ -1,5 +1,31 @@
1
1
  import { AgentComposeClient } from "../client.js";
2
- import type { WorkflowCtx } from "../types/workflow.js";
2
+ import { getActiveStep, nextPauseOrdinalInActiveStep } from "../active-step.js";
3
+ import type { InvokeChild } from "../types/execution-context.js";
4
+
5
+ /**
6
+ * Derive the deterministic per-call `Idempotency-Key` for a `ctx.invokeChild`
7
+ * dispatch: `invoke-child:<parentRunId>:step<stepIndex>:<childName>:<ordinal>`.
8
+ *
9
+ * Replay safety: a replayed step re-runs its body from the top, so the k-th
10
+ * `invokeChild(name)` call in a step re-derives the SAME key (the per-scope
11
+ * ordinal counter lives on the active-step state, which resets identically on
12
+ * every (re-)entry — the `nextPauseOrdinalInActiveStep` pattern). The server's
13
+ * idempotency window then returns the original child run instead of
14
+ * double-dispatching. Outside step execution (local dev, tests) there is no
15
+ * stable coordinate to key on — returns null and the dispatch is unkeyed,
16
+ * exactly the old behavior.
17
+ *
18
+ * Key syntax matches the server's `Idempotency-Key` grammar
19
+ * (`[A-Za-z0-9_\-:.]{1,255}`): runId is a UUID, step index a number, and
20
+ * workflow names are kebab-case.
21
+ */
22
+ export function deriveInvokeChildIdempotencyKey(parentRunId: string, childName: string): string | null {
23
+ const step = getActiveStep();
24
+ if (!step) return null;
25
+ const ordinal = nextPauseOrdinalInActiveStep(`invoke-child:${childName}`);
26
+ if (ordinal === null) return null;
27
+ return `invoke-child:${parentRunId}:step${step.stepIndex}:${childName}:${ordinal}`;
28
+ }
3
29
 
4
30
  /**
5
31
  * Build the public-API child workflow invoker used by legacy and sandboxed
@@ -9,7 +35,7 @@ import type { WorkflowCtx } from "../types/workflow.js";
9
35
  export function buildInvokeChild(
10
36
  runId: string,
11
37
  opts: { fallbackBaseUrl?: string; defaultFactorySlug?: string } = {},
12
- ): WorkflowCtx["invokeChild"] {
38
+ ): InvokeChild {
13
39
  let childClient: AgentComposeClient | null = null;
14
40
  const getChildClient = (): AgentComposeClient => {
15
41
  if (childClient) return childClient;
@@ -21,15 +47,25 @@ export function buildInvokeChild(
21
47
  childClient = new AgentComposeClient({ apiKey, baseUrl });
22
48
  return childClient;
23
49
  };
24
- return (name, input, childOpts) => getChildClient().invokeAndWait(name, input, {
25
- ...childOpts,
26
- parentRunId: runId,
27
- // The runner sets `AGENT_COMPOSE_FACTORY` (the run's factory slug — see
28
- // activities.ts loadRunnerEnvs). Default the child to it so it lands in the
29
- // SAME factory as the parent — the per-run API key is factory-scoped, so a
30
- // child dispatched into another factory 403s. (Was reading the never-set
31
- // `AGENT_COMPOSE_FACTORY_SLUG`, silently falling back to "default".)
32
- factorySlug: childOpts?.factorySlug ?? opts.defaultFactorySlug
33
- ?? process.env.AGENT_COMPOSE_FACTORY ?? process.env.AGENT_COMPOSE_FACTORY_SLUG ?? "default",
34
- });
50
+ return (name, input, childOpts) => {
51
+ // Replay-safe dispatch: derive a deterministic per-step key so a step
52
+ // re-entered after pause/resume (or a crash-replayed attempt) dedupes to
53
+ // the original child run instead of double-dispatching. An explicit
54
+ // caller-supplied key wins.
55
+ const idempotencyKey = childOpts?.idempotencyKey
56
+ ?? deriveInvokeChildIdempotencyKey(runId, name)
57
+ ?? undefined;
58
+ return getChildClient().invokeAndWait(name, input, {
59
+ ...childOpts,
60
+ ...(idempotencyKey !== undefined ? { idempotencyKey } : {}),
61
+ parentRunId: runId,
62
+ // The runner sets `AGENT_COMPOSE_FACTORY` (the run's factory slug — see
63
+ // activities.ts loadRunnerEnvs). Default the child to it so it lands in the
64
+ // SAME factory as the parent — the per-run API key is factory-scoped, so a
65
+ // child dispatched into another factory 403s. (Was reading the never-set
66
+ // `AGENT_COMPOSE_FACTORY_SLUG`, silently falling back to "default".)
67
+ factorySlug: childOpts?.factorySlug ?? opts.defaultFactorySlug
68
+ ?? process.env.AGENT_COMPOSE_FACTORY ?? process.env.AGENT_COMPOSE_FACTORY_SLUG ?? "default",
69
+ });
70
+ };
35
71
  }