@dogpile/sdk 0.3.1 → 0.4.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 (56) hide show
  1. package/CHANGELOG.md +136 -0
  2. package/README.md +1 -0
  3. package/dist/browser/index.js +1595 -54
  4. package/dist/browser/index.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/providers/openai-compatible.d.ts +11 -0
  8. package/dist/providers/openai-compatible.d.ts.map +1 -1
  9. package/dist/providers/openai-compatible.js +87 -2
  10. package/dist/providers/openai-compatible.js.map +1 -1
  11. package/dist/runtime/cancellation.d.ts +26 -0
  12. package/dist/runtime/cancellation.d.ts.map +1 -1
  13. package/dist/runtime/cancellation.js +38 -1
  14. package/dist/runtime/cancellation.js.map +1 -1
  15. package/dist/runtime/coordinator.d.ts +74 -1
  16. package/dist/runtime/coordinator.d.ts.map +1 -1
  17. package/dist/runtime/coordinator.js +932 -25
  18. package/dist/runtime/coordinator.js.map +1 -1
  19. package/dist/runtime/decisions.d.ts +25 -3
  20. package/dist/runtime/decisions.d.ts.map +1 -1
  21. package/dist/runtime/decisions.js +241 -3
  22. package/dist/runtime/decisions.js.map +1 -1
  23. package/dist/runtime/defaults.d.ts +37 -1
  24. package/dist/runtime/defaults.d.ts.map +1 -1
  25. package/dist/runtime/defaults.js +347 -0
  26. package/dist/runtime/defaults.js.map +1 -1
  27. package/dist/runtime/engine.d.ts.map +1 -1
  28. package/dist/runtime/engine.js +254 -24
  29. package/dist/runtime/engine.js.map +1 -1
  30. package/dist/runtime/sequential.d.ts.map +1 -1
  31. package/dist/runtime/sequential.js +8 -1
  32. package/dist/runtime/sequential.js.map +1 -1
  33. package/dist/runtime/validation.d.ts +10 -0
  34. package/dist/runtime/validation.d.ts.map +1 -1
  35. package/dist/runtime/validation.js +73 -0
  36. package/dist/runtime/validation.js.map +1 -1
  37. package/dist/types/events.d.ts +329 -8
  38. package/dist/types/events.d.ts.map +1 -1
  39. package/dist/types/replay.d.ts +5 -1
  40. package/dist/types/replay.d.ts.map +1 -1
  41. package/dist/types.d.ts +131 -5
  42. package/dist/types.d.ts.map +1 -1
  43. package/dist/types.js.map +1 -1
  44. package/package.json +1 -1
  45. package/src/index.ts +10 -0
  46. package/src/providers/openai-compatible.ts +82 -3
  47. package/src/runtime/cancellation.ts +59 -1
  48. package/src/runtime/coordinator.ts +1170 -25
  49. package/src/runtime/decisions.ts +307 -4
  50. package/src/runtime/defaults.ts +376 -0
  51. package/src/runtime/engine.ts +363 -24
  52. package/src/runtime/sequential.ts +9 -1
  53. package/src/runtime/validation.ts +81 -0
  54. package/src/types/events.ts +359 -8
  55. package/src/types/replay.ts +12 -1
  56. package/src/types.ts +147 -3
package/src/types.ts CHANGED
@@ -87,6 +87,14 @@ export type DogpileProviderInvalidRequestError = DogpileErrorBase<"provider-inva
87
87
  export type DogpileProviderInvalidResponseError = DogpileErrorBase<"provider-invalid-response">;
88
88
  export type DogpileProviderNotFoundError = DogpileErrorBase<"provider-not-found">;
89
89
  export type DogpileProviderRateLimitedError = DogpileErrorBase<"provider-rate-limited">;
90
+ /**
91
+ * Provider timeout errors may include `detail.source?: "provider" | "engine"`.
92
+ *
93
+ * Absence is backwards-compatible and should be interpreted as `"provider"`.
94
+ * `"engine"` means a child engine's own deadline expired before the provider
95
+ * returned; parent budget propagation remains `code: "aborted"` with
96
+ * `detail.reason: "timeout"`.
97
+ */
90
98
  export type DogpileProviderTimeoutError = DogpileErrorBase<"provider-timeout">;
91
99
  export type DogpileProviderUnavailableError = DogpileErrorBase<"provider-unavailable">;
92
100
  export type DogpileProviderUnsupportedError = DogpileErrorBase<"provider-unsupported">;
@@ -887,6 +895,14 @@ export interface ConfiguredModelProvider {
887
895
  * support incremental output and for callers that prefer batch execution.
888
896
  */
889
897
  stream?(request: ModelRequest): AsyncIterable<ModelOutputChunk>;
898
+ /**
899
+ * Optional provider hints for the runtime. Absent or omitted is treated as
900
+ * `remote` for concurrency clamping (CONCURRENCY-02 / Phase 3 D-01).
901
+ */
902
+ readonly metadata?: {
903
+ /** Locality hint for dispatch clamping. Absent -> "remote" for clamping. */
904
+ readonly locality?: "local" | "remote";
905
+ };
890
906
  }
891
907
 
892
908
  /**
@@ -1284,16 +1300,19 @@ export type {
1284
1300
 
1285
1301
  // Events: see src/types/events.ts
1286
1302
  import type {
1303
+ AbortedEvent,
1287
1304
  AgentDecision,
1288
1305
  AgentParticipation,
1289
1306
  BroadcastContribution,
1290
1307
  BroadcastEvent,
1291
1308
  BudgetStopEvent,
1309
+ DelegateAgentDecision,
1292
1310
  FinalEvent,
1293
1311
  ModelActivityEvent,
1294
1312
  ModelOutputChunkEvent,
1295
1313
  ModelRequestEvent,
1296
1314
  ModelResponseEvent,
1315
+ ParticipateAgentDecision,
1297
1316
  RoleAssignmentEvent,
1298
1317
  RunEvent,
1299
1318
  StreamCompletionEvent,
@@ -1301,6 +1320,13 @@ import type {
1301
1320
  StreamEvent,
1302
1321
  StreamLifecycleEvent,
1303
1322
  StreamOutputEvent,
1323
+ SubRunBudgetClampedEvent,
1324
+ SubRunCompletedEvent,
1325
+ SubRunConcurrencyClampedEvent,
1326
+ SubRunFailedEvent,
1327
+ SubRunParentAbortedEvent,
1328
+ SubRunQueuedEvent,
1329
+ SubRunStartedEvent,
1304
1330
  ToolActivityEvent,
1305
1331
  ToolCallEvent,
1306
1332
  ToolResultEvent,
@@ -1308,8 +1334,11 @@ import type {
1308
1334
  TurnEvent
1309
1335
  } from "./types/events.js";
1310
1336
  export type {
1337
+ AbortedEvent,
1311
1338
  AgentDecision,
1312
1339
  AgentParticipation,
1340
+ DelegateAgentDecision,
1341
+ ParticipateAgentDecision,
1313
1342
  BroadcastContribution,
1314
1343
  BroadcastEvent,
1315
1344
  BudgetStopEvent,
@@ -1325,6 +1354,13 @@ export type {
1325
1354
  StreamEvent,
1326
1355
  StreamLifecycleEvent,
1327
1356
  StreamOutputEvent,
1357
+ SubRunBudgetClampedEvent,
1358
+ SubRunCompletedEvent,
1359
+ SubRunConcurrencyClampedEvent,
1360
+ SubRunFailedEvent,
1361
+ SubRunParentAbortedEvent,
1362
+ SubRunQueuedEvent,
1363
+ SubRunStartedEvent,
1328
1364
  ToolActivityEvent,
1329
1365
  ToolCallEvent,
1330
1366
  ToolResultEvent,
@@ -1372,7 +1408,7 @@ export interface TranscriptEntry {
1372
1408
  /** Text produced by the agent. */
1373
1409
  readonly output: string;
1374
1410
  /** Optional structured role/participation decision parsed from model output. */
1375
- readonly decision?: AgentDecision;
1411
+ readonly decision?: AgentDecision | readonly DelegateAgentDecision[];
1376
1412
  /** Ordered runtime tool calls and results requested during this turn. */
1377
1413
  readonly toolCalls?: readonly TranscriptToolCall[];
1378
1414
  }
@@ -1535,6 +1571,17 @@ export interface Trace {
1535
1571
  readonly providerCalls: readonly ReplayTraceProviderCall[];
1536
1572
  /** Final output artifact for replay consumers. */
1537
1573
  readonly finalOutput: ReplayTraceFinalOutput;
1574
+ /** Internal hand-off for fail-fast coordinator child failure handling. */
1575
+ readonly triggeringFailureForAbortMode?: {
1576
+ readonly childRunId: string;
1577
+ readonly intent: string;
1578
+ readonly error: {
1579
+ readonly code: string;
1580
+ readonly message: string;
1581
+ readonly detail?: { readonly reason?: string };
1582
+ };
1583
+ readonly partialCost: { readonly usd: number };
1584
+ };
1538
1585
  /**
1539
1586
  * Ordered coordination and lifecycle events.
1540
1587
  *
@@ -1760,8 +1807,48 @@ export interface DogpileOptions extends BudgetCostTierOptions {
1760
1807
  readonly seed?: string | number;
1761
1808
  /** Optional caller cancellation signal passed to provider-facing model requests. */
1762
1809
  readonly signal?: AbortSignal;
1810
+ /**
1811
+ * Maximum coordinator → sub-run recursion depth.
1812
+ *
1813
+ * Defaults to 4. Per-run values can only LOWER the engine ceiling; raising
1814
+ * is silently capped via
1815
+ * `effectiveMaxDepth = Math.min(engineMaxDepth, runMaxDepth ?? Infinity)`.
1816
+ * Depth overflow throws `DogpileError({ code: "invalid-configuration",
1817
+ * detail: { kind: "delegate-validation", reason: "depth-overflow" } })`.
1818
+ */
1819
+ readonly maxDepth?: number;
1820
+ /**
1821
+ * Maximum delegated child runs that may execute in parallel.
1822
+ *
1823
+ * Defaults to 4. Per-run and per-decision values can only lower the engine
1824
+ * ceiling; the effective value is `min(engine, run ?? Infinity, decision ?? Infinity)`.
1825
+ */
1826
+ readonly maxConcurrentChildren?: number;
1827
+ /**
1828
+ * Fallback timeout (milliseconds) applied to delegated sub-runs when neither
1829
+ * the parent's `budget.timeoutMs` nor the decision-level
1830
+ * `decision.budget.timeoutMs` specifies one (BUDGET-02 / D-14).
1831
+ *
1832
+ * Precedence (most specific wins):
1833
+ * `decision.budget.timeoutMs` > parent's remaining deadline (when parent has
1834
+ * `budget.timeoutMs`) > `defaultSubRunTimeoutMs` > undefined.
1835
+ *
1836
+ * Default: `undefined` (preserves the "no sub-run timeout" posture).
1837
+ */
1838
+ readonly defaultSubRunTimeoutMs?: number;
1839
+ /**
1840
+ * Controls how coordinator runs react after a real delegated child failure.
1841
+ *
1842
+ * Defaults to `"continue"`, which re-issues the coordinator plan turn with
1843
+ * structured failure context. `"abort"` skips that follow-up plan turn and
1844
+ * records the triggering child failure for the unhandled-failure throw path.
1845
+ */
1846
+ readonly onChildFailure?: OnChildFailureMode;
1763
1847
  }
1764
1848
 
1849
+ /** Coordinator behavior after a real child failure in a delegated dispatch wave. */
1850
+ export type OnChildFailureMode = "continue" | "abort";
1851
+
1765
1852
  /**
1766
1853
  * Low-level engine configuration for reusable protocol execution.
1767
1854
  *
@@ -1824,6 +1911,63 @@ export interface EngineOptions {
1824
1911
  readonly seed?: string | number;
1825
1912
  /** Optional caller cancellation signal passed to provider-facing model requests. */
1826
1913
  readonly signal?: AbortSignal;
1914
+ /**
1915
+ * Maximum coordinator → sub-run recursion depth ceiling.
1916
+ *
1917
+ * Defaults to 4. Per-run lowering happens at `engine.run` / `engine.stream`
1918
+ * call sites via {@link RunCallOptions.maxDepth}; per-run can only lower this
1919
+ * ceiling. Depth overflow throws `DogpileError({ code: "invalid-configuration",
1920
+ * detail: { kind: "delegate-validation", reason: "depth-overflow" } })`.
1921
+ */
1922
+ readonly maxDepth?: number;
1923
+ /**
1924
+ * Maximum delegated child runs that may execute in parallel.
1925
+ *
1926
+ * Defaults to 4. Per-run lowering happens at `engine.run` / `engine.stream`
1927
+ * call sites via {@link RunCallOptions.maxConcurrentChildren}.
1928
+ */
1929
+ readonly maxConcurrentChildren?: number;
1930
+ /**
1931
+ * Fallback timeout (milliseconds) applied to delegated sub-runs when neither
1932
+ * the parent's `budget.timeoutMs` nor the decision-level
1933
+ * `decision.budget.timeoutMs` specifies one (BUDGET-02 / D-14).
1934
+ *
1935
+ * Precedence (most specific wins):
1936
+ * `decision.budget.timeoutMs` > parent's remaining deadline (when parent has
1937
+ * `budget.timeoutMs`) > `defaultSubRunTimeoutMs` > undefined.
1938
+ *
1939
+ * Default: `undefined` (preserves the "no sub-run timeout" posture).
1940
+ */
1941
+ readonly defaultSubRunTimeoutMs?: number;
1942
+ /**
1943
+ * Controls how coordinator runs react after a real delegated child failure.
1944
+ *
1945
+ * Defaults to `"continue"`. `"abort"` skips the follow-up coordinator plan
1946
+ * turn and records the triggering child failure for fail-fast callers.
1947
+ */
1948
+ readonly onChildFailure?: OnChildFailureMode;
1949
+ }
1950
+
1951
+ /**
1952
+ * Per-call overrides accepted by {@link Engine.run} and {@link Engine.stream}.
1953
+ *
1954
+ * @remarks
1955
+ * Only fields that should be controllable per-mission live here. Today the
1956
+ * fields are controls that can only LOWER the engine's ceiling.
1957
+ */
1958
+ export interface RunCallOptions {
1959
+ /**
1960
+ * Per-run maximum recursion depth. Cannot raise the engine's ceiling — the
1961
+ * effective value is `Math.min(engine.maxDepth ?? 4, runOptions.maxDepth ?? Infinity)`.
1962
+ */
1963
+ readonly maxDepth?: number;
1964
+ /**
1965
+ * Per-run delegated child concurrency ceiling. Cannot raise the engine's
1966
+ * ceiling.
1967
+ */
1968
+ readonly maxConcurrentChildren?: number;
1969
+ /** Per-run child-failure behavior. Overrides the engine default. */
1970
+ readonly onChildFailure?: OnChildFailureMode;
1827
1971
  }
1828
1972
 
1829
1973
  /**
@@ -1903,7 +2047,7 @@ export interface StreamSubscription {
1903
2047
  */
1904
2048
  export interface Engine {
1905
2049
  /** Execute a mission to completion and return the final result. */
1906
- run(intent: string): Promise<RunResult>;
2050
+ run(intent: string, options?: RunCallOptions): Promise<RunResult>;
1907
2051
  /** Stream a mission's events while preserving access to the final result. */
1908
- stream(intent: string): StreamHandle;
2052
+ stream(intent: string, options?: RunCallOptions): StreamHandle;
1909
2053
  }