@studio-foundation/contracts 0.13.0 → 0.15.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.
package/README.md CHANGED
@@ -67,7 +67,7 @@ Nothing imports upward. If you find yourself adding a dep here, you're solving t
67
67
  | `tool-plugin.ts` | `ToolPluginDef`, `ToolCommandDef`, `ShellExecute`, `BuiltinExecute`, `ParameterDef` |
68
68
  | `runner-events.ts` | `RunnerCallbacks`, `ToolCallStartEvent`, `ToolCallCompleteEvent`, `AgentThinkingEvent`, `AgentProgressEvent`, `AgentTokenEvent` |
69
69
  | `spawner.ts` | `RunSpawner`, `SpawnConfig`, `SpawnResult` |
70
- | `integration-plugin.ts` | `IntegrationPluginDef` |
70
+ | `trigger.ts` | `TriggerDef` |
71
71
 
72
72
  ## Key types
73
73
 
package/dist/agent.d.ts CHANGED
@@ -1,3 +1,13 @@
1
+ /**
2
+ * What an agent asks the provider to do about prompt caching.
3
+ *
4
+ * - `auto` (default) — cache only when the stage is expected to run more than one
5
+ * turn against the same prefix, which is what makes a cache write pay for itself.
6
+ * - `on` — always cache. For a fan-out whose items have been measured to share a
7
+ * prefix long enough to beat the write premium.
8
+ * - `off` — never cache, whatever the stage looks like.
9
+ */
10
+ export type PromptCacheMode = 'auto' | 'on' | 'off';
1
11
  export interface AgentConfig {
2
12
  name: string;
3
13
  description?: string;
@@ -10,6 +20,8 @@ export interface AgentConfig {
10
20
  temperature?: number;
11
21
  max_tokens?: number;
12
22
  anonymize?: boolean;
23
+ /** Prompt-cache policy for this agent's calls. Default `auto`. */
24
+ prompt_cache?: PromptCacheMode;
13
25
  }
14
26
  /** AgentConfig after defaults have been applied — provider and model are guaranteed. */
15
27
  export interface ResolvedAgentConfig extends AgentConfig {
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC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AAM,EAAE,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kEAAkE;IAClE,YAAY,CAAC,EAAE,eAAe,CAAC;CAChC;AAED,wFAAwF;AACxF,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC;AAEvC,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
package/dist/index.d.ts CHANGED
@@ -5,10 +5,11 @@ export * from './agent.js';
5
5
  export * from './run.js';
6
6
  export * from './validation.js';
7
7
  export * from './provider.js';
8
+ export * from './usage.js';
8
9
  export * from './errors.js';
9
10
  export * from './context-pack.js';
10
11
  export * from './tool-plugin.js';
11
12
  export * from './runner-events.js';
12
13
  export * from './spawner.js';
13
- export * from './integration-plugin.js';
14
+ export * from './trigger.js';
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -7,10 +7,11 @@ export * from './agent.js';
7
7
  export * from './run.js';
8
8
  export * from './validation.js';
9
9
  export * from './provider.js';
10
+ export * from './usage.js';
10
11
  export * from './errors.js';
11
12
  export * from './context-pack.js';
12
13
  export * from './tool-plugin.js';
13
14
  export * from './runner-events.js';
14
15
  export * from './spawner.js';
15
- export * from './integration-plugin.js';
16
+ export * from './trigger.js';
16
17
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,oDAAoD;AAEpD,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,cAAc,CAAC;AAC7B,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,oDAAoD;AAEpD,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
@@ -123,6 +123,51 @@ export interface MapStage {
123
123
  * restart between runs.
124
124
  */
125
125
  resume?: boolean;
126
+ /**
127
+ * Dispatch this fan-out's LLM calls as batches instead of one synchronous
128
+ * request per item (default: off). `true` takes every default below.
129
+ *
130
+ * The items of a fan-out are independent and nothing is waiting on any single
131
+ * one of them, which is exactly what a vendor batch endpoint is priced for:
132
+ * Anthropic's Message Batches API bills every token — input, output, cache
133
+ * write, cache read — at 50% of the synchronous rate, in exchange for up to
134
+ * 24h to finish. On a bulk stage that is the largest cost lever there is.
135
+ *
136
+ * What it changes, and what it does not:
137
+ * - Items still run as ordinary child runs. Contracts, RALPH, hooks,
138
+ * post-validation and the `resume` cache all behave identically; a cached
139
+ * item is simply never dispatched.
140
+ * - Validation stays per item, after the batch comes back. An item that
141
+ * fails retries into the *next* batch, so rounds shrink instead of the
142
+ * retry loop paying full price per item.
143
+ * - `concurrency` defaults to `min(items, max_size)` here instead of 1 —
144
+ * items must be in flight together to share a batch. An explicit
145
+ * `concurrency` is still honoured, and caps the batch at that size.
146
+ * - Nothing streams: a batched response arrives whole, so `--live` shows no
147
+ * tokens for these items.
148
+ * - A provider with no batch endpoint (mock, ollama, claude-code) runs the
149
+ * stage exactly as it would without this key — correct, just not cheaper.
150
+ */
151
+ batch?: boolean | MapBatchConfig;
152
+ }
153
+ /** Tuning for a `map` stage's batched dispatch. Every field has a default. */
154
+ export interface MapBatchConfig {
155
+ /** Requests per batch before one is sent without waiting for the rest. Default 500. */
156
+ max_size?: number;
157
+ /** How often to ask whether the batch has ended. Default 15000. */
158
+ poll_interval_ms?: number;
159
+ /**
160
+ * Give up on a batch after this long, failing its requests. Default 86400000
161
+ * (24h — the API's own expiry). A batch has no per-call timeout; this is the
162
+ * whole-stage budget that replaces one.
163
+ */
164
+ max_wait_ms?: number;
165
+ /**
166
+ * Send what is parked after this long with no new request arriving, even
167
+ * while an item is still busy elsewhere. Default 30000, `0` disables it.
168
+ * Without it one slow item would hold the whole batch.
169
+ */
170
+ flush_after_ms?: number;
126
171
  }
127
172
  /**
128
173
  * A call stage: run a named pipeline once, inline, and expose its output to
@@ -1 +1 @@
1
- {"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,YAAY,CAAC;IACnB,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,cAAc,EAAE,CAAC;IACrC,YA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AAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,IAAI,UAAU,CAEtE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,IAAI,QAAQ,CAElE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,IAAI,SAAS,CAEpE"}
@@ -1 +1 @@
1
- {"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,iCAAiC;AAiLjC,MAAM,UAAU,YAAY,CAAC,KAAoB;IAC/C,OAAO,OAAO,IAAI,KAAK,IAAI,QAAQ,IAAI,KAAK,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAoB;IAC7C,OAAO,KAAK,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAoB;IAC9C,OAAO,MAAM,IAAI,KAAK,CAAC;AACzB,CAAC"}
1
+ {"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,iCAAiC;AA+NjC,MAAM,UAAU,YAAY,CAAC,KAAoB;IAC/C,OAAO,OAAO,IAAI,KAAK,IAAI,QAAQ,IAAI,KAAK,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAoB;IAC7C,OAAO,KAAK,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAoB;IAC9C,OAAO,MAAM,IAAI,KAAK,CAAC;AACzB,CAAC"}
@@ -1,3 +1,4 @@
1
+ import type { TokenUsage } from './usage';
1
2
  export interface LLMRequest {
2
3
  model: string;
3
4
  messages: Message[];
@@ -6,6 +7,15 @@ export interface LLMRequest {
6
7
  max_tokens?: number;
7
8
  stage_name?: string;
8
9
  json_mode?: boolean;
10
+ /**
11
+ * Whether the provider should mark this call's stable prefix (system prompt +
12
+ * tool definitions) as cacheable. A cache write is billed above the plain input
13
+ * rate and only pays for itself once something reads it back, so a call that
14
+ * will never have a successor costs MORE with caching on than off. The caller
15
+ * decides — it is the only party that knows whether a second turn is coming.
16
+ * Absent means no: providers must not cache speculatively.
17
+ */
18
+ cache_prompt?: boolean;
9
19
  }
10
20
  export interface Message {
11
21
  role: 'system' | 'user' | 'assistant';
@@ -19,13 +29,8 @@ export interface LLMResponse {
19
29
  arguments: Record<string, unknown>;
20
30
  }>;
21
31
  finish_reason: string;
22
- usage?: {
23
- prompt_tokens: number;
24
- completion_tokens: number;
25
- total_tokens: number;
26
- cached_input_tokens?: number;
27
- cache_creation_tokens?: number;
28
- };
32
+ /** What the call cost, as the provider reported it. See ./usage.ts. */
33
+ usage?: TokenUsage;
29
34
  }
30
35
  export interface ToolDefinition {
31
36
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,KAAK,CAAC;QACjB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,E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,CAAC;KACpC,CAAC,CAAC;IACH,aAAa,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC"}
package/dist/run.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { StageStatus } from './stage';
2
2
  import type { TaskStatus } from './task';
3
+ import type { TokenUsage } from './usage';
3
4
  export type AgentStatus = 'pending' | 'running' | 'success' | 'failed';
4
5
  export interface PipelineRun {
5
6
  id: string;
@@ -23,6 +24,7 @@ export interface StageRun {
23
24
  output?: unknown;
24
25
  skipped_reason?: string;
25
26
  child_run_id?: string;
27
+ token_usage?: TokenUsage;
26
28
  }
27
29
  export interface TaskRun {
28
30
  id: string;
package/dist/run.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEvE,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,WAAW,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;IAIvB,GAAG,CAAC,EAAE,M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;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
package/dist/spawner.d.ts CHANGED
@@ -1,13 +1,34 @@
1
+ import type { TokenUsage } from './usage';
2
+ /**
3
+ * Per-spawn execution overrides. In-process spawners honour them; a remote
4
+ * spawner ignores them, because they name objects that live in this process.
5
+ *
6
+ * Typed as `unknown` on purpose: contracts is a leaf package (INV-04) and the
7
+ * provider registry lives in runner, so the type cannot be named here. The
8
+ * in-process spawner casts it back.
9
+ */
10
+ export interface SpawnOverrides {
11
+ /**
12
+ * Replaces the engine's provider registry for this child run and its
13
+ * descendants. Set by a `map` stage running with `batch:` — the substituted
14
+ * registry parks the child's LLM calls in the parent's batch window instead
15
+ * of sending them one by one.
16
+ */
17
+ providerRegistry?: unknown;
18
+ }
1
19
  export interface SpawnConfig {
2
20
  pipeline: string;
3
21
  input: Record<string, unknown>;
4
22
  parentRunId: string;
5
23
  depth: number;
24
+ overrides?: SpawnOverrides;
6
25
  }
7
26
  export interface SpawnResult {
8
27
  run_id: string;
9
28
  status: string;
10
29
  output: unknown;
30
+ /** What the child run spent, summed over its stages. Absent when unreported. */
31
+ token_usage?: TokenUsage;
11
32
  }
12
33
  export interface RunSpawner {
13
34
  spawnAndWait(config: SpawnConfig): Promise<SpawnResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"spawner.d.ts","sourceRoot":"","sources":["../src/spawner.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACzD"}
1
+ {"version":3,"file":"spawner.d.ts","sourceRoot":"","sources":["../src/spawner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,cAAc,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,gFAAgF;IAChF,WAAW,CAAC,EAAE,UAAU,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACzB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACzD"}
@@ -0,0 +1,38 @@
1
+ export interface TriggerDef {
2
+ name: string;
3
+ version: number;
4
+ description?: string;
5
+ /** Pipeline to launch when the webhook matches. */
6
+ pipeline: string;
7
+ /** Omitted entirely, every signed-or-not delivery matches — same as an empty block. */
8
+ webhook?: {
9
+ hmac?: {
10
+ /** Request header carrying the hex signature, e.g. 'x-hub-signature-256'. */
11
+ header: string;
12
+ /** Shared secret; `${VAR}` is resolved from the environment at load. */
13
+ secret: string;
14
+ };
15
+ /** Conditions over `payload.<path>`, same syntax as a stage `when:`. All must hold. */
16
+ when?: string[];
17
+ };
18
+ /** Pipeline input, with `{{payload.<path>}}` references. */
19
+ input?: Record<string, unknown>;
20
+ /** Run metadata, with `{{payload.<path>}}` references. */
21
+ meta?: Record<string, unknown>;
22
+ /** What to show in the trigger log, with `{{payload.<path>}}` references. */
23
+ log?: {
24
+ external_id?: string;
25
+ external_label?: string;
26
+ external_url?: string;
27
+ };
28
+ /**
29
+ * Command run when a triggered run does not succeed. Values reach it through
30
+ * the environment (`STUDIO_RUN_ID`, `STUDIO_META`, …), never interpolated into
31
+ * the command string — the payload that produced them is untrusted.
32
+ */
33
+ on_failure?: {
34
+ command: string;
35
+ timeout_ms?: number;
36
+ };
37
+ }
38
+ //# sourceMappingURL=trigger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trigger.d.ts","sourceRoot":"","sources":["../src/trigger.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,uFAAuF;IACvF,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE;YACL,6EAA6E;YAC7E,MAAM,EAAE,MAAM,CAAC;YACf,wEAAwE;YACxE,MAAM,EAAE,MAAM,CAAC;SAChB,CAAC;QACF,uFAAuF;QACvF,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;KACjB,CAAC;IACF,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,6EAA6E;IAC7E,GAAG,CAAC,EAAE;QACJ,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;IACF;;;;OAIG;IACH,UAAU,CAAC,EAAE;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH"}
@@ -0,0 +1,6 @@
1
+ // A `.trigger.yaml` — an inbound webhook that launches a pipeline run.
2
+ //
3
+ // Triggers cover the one thing tools and MCP servers cannot: an external system
4
+ // pushing to Studio. Everything a trigger does *outbound* belongs in a tool.
5
+ export {};
6
+ //# sourceMappingURL=trigger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trigger.js","sourceRoot":"","sources":["../src/trigger.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,EAAE;AACF,gFAAgF;AAChF,6EAA6E"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Token counts for a single model.
3
+ *
4
+ * The four input/output fields are disjoint, because each is billed at its own
5
+ * rate — a run that reads 200k tokens from cache and one that sends 200k fresh
6
+ * differ by an order of magnitude in cost, and a single `prompt_tokens` number
7
+ * cannot tell them apart. Providers report the split differently (Anthropic
8
+ * excludes cache counts from its input total, OpenAI includes them); every
9
+ * Studio provider normalizes to the definitions below.
10
+ */
11
+ export interface ModelTokenUsage {
12
+ /** Input tokens billed at full rate — cache reads and writes excluded. */
13
+ prompt_tokens: number;
14
+ /** Output tokens generated. */
15
+ completion_tokens: number;
16
+ /** Every token the call consumed: prompt + cached + cache-creation + completion. */
17
+ total_tokens: number;
18
+ /** Input tokens served from the provider's prompt cache (billed at a discount). */
19
+ cached_input_tokens?: number;
20
+ /** Input tokens written to the provider's prompt cache (billed at a premium). */
21
+ cache_creation_tokens?: number;
22
+ }
23
+ export interface TokenUsage extends ModelTokenUsage {
24
+ /**
25
+ * Per-model split of the same counts. One entry for an ordinary call; several
26
+ * when a single call spans models (the claude CLI reports one per model it
27
+ * used, subagents included). The top-level counts are always the sum of these.
28
+ */
29
+ by_model?: Record<string, ModelTokenUsage>;
30
+ }
31
+ /** A zeroed accumulator. */
32
+ export declare function emptyTokenUsage(): TokenUsage;
33
+ /**
34
+ * Attach a model name to a set of counts, so the by_model split survives every
35
+ * later merge. Providers that know which model answered call this instead of
36
+ * building the map by hand.
37
+ */
38
+ export declare function withModel(model: string | undefined, counts: ModelTokenUsage): TokenUsage;
39
+ /**
40
+ * Sum `add` into `target` in place, merging the per-model split. `target` must be
41
+ * an accumulator you own — `emptyTokenUsage()` or a clone.
42
+ */
43
+ export declare function accumulateTokenUsage(target: TokenUsage, add: TokenUsage | undefined): TokenUsage;
44
+ /**
45
+ * Sum any number of usages. Returns undefined when nothing was reported, so an
46
+ * absent usage stays absent instead of becoming a misleading row of zeros.
47
+ */
48
+ export declare function sumTokenUsage(usages: Array<TokenUsage | undefined>): TokenUsage | undefined;
49
+ //# sourceMappingURL=usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH,MAAM,WAAW,eAAe;IAC9B,0EAA0E;IAC1E,aAAa,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oFAAoF;IACpF,YAAY,EAAE,MAAM,CAAC;IACrB,mFAAmF;IACnF,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,iFAAiF;IACjF,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,UAAW,SAAQ,eAAe;IACjD;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAC5C;AAED,4BAA4B;AAC5B,wBAAgB,eAAe,IAAI,UAAU,CAE5C;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,eAAe,GAAG,UAAU,CAGxF;AAcD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,SAAS,GAAG,UAAU,CAehG;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,GAAG,SAAS,CAAC,GAAG,UAAU,GAAG,SAAS,CAM3F"}
package/dist/usage.js ADDED
@@ -0,0 +1,68 @@
1
+ // Token accounting — the shape every provider reports and every consumer sums.
2
+ //
3
+ // One type, three hops: a provider fills it per LLM call, the runner accumulates
4
+ // it across the turns of one agent run, the engine stamps it on the stage and the
5
+ // CLI writes it to the run JSONL. Measuring what a run cost is then a `jq` pass
6
+ // over `.studio/runs/<run>.jsonl`, not a correlation of provider session files
7
+ // against stage timestamps.
8
+ /** A zeroed accumulator. */
9
+ export function emptyTokenUsage() {
10
+ return { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 };
11
+ }
12
+ /**
13
+ * Attach a model name to a set of counts, so the by_model split survives every
14
+ * later merge. Providers that know which model answered call this instead of
15
+ * building the map by hand.
16
+ */
17
+ export function withModel(model, counts) {
18
+ if (!model)
19
+ return { ...counts };
20
+ return { ...counts, by_model: { [model]: { ...counts } } };
21
+ }
22
+ function addInto(target, add) {
23
+ target.prompt_tokens += add.prompt_tokens;
24
+ target.completion_tokens += add.completion_tokens;
25
+ target.total_tokens += add.total_tokens;
26
+ if (add.cached_input_tokens !== undefined) {
27
+ target.cached_input_tokens = (target.cached_input_tokens ?? 0) + add.cached_input_tokens;
28
+ }
29
+ if (add.cache_creation_tokens !== undefined) {
30
+ target.cache_creation_tokens = (target.cache_creation_tokens ?? 0) + add.cache_creation_tokens;
31
+ }
32
+ }
33
+ /**
34
+ * Sum `add` into `target` in place, merging the per-model split. `target` must be
35
+ * an accumulator you own — `emptyTokenUsage()` or a clone.
36
+ */
37
+ export function accumulateTokenUsage(target, add) {
38
+ if (!add)
39
+ return target;
40
+ addInto(target, add);
41
+ if (add.by_model) {
42
+ target.by_model ??= {};
43
+ for (const [model, counts] of Object.entries(add.by_model)) {
44
+ const existing = target.by_model[model];
45
+ if (existing) {
46
+ addInto(existing, counts);
47
+ }
48
+ else {
49
+ target.by_model[model] = { ...counts };
50
+ }
51
+ }
52
+ }
53
+ return target;
54
+ }
55
+ /**
56
+ * Sum any number of usages. Returns undefined when nothing was reported, so an
57
+ * absent usage stays absent instead of becoming a misleading row of zeros.
58
+ */
59
+ export function sumTokenUsage(usages) {
60
+ const reported = usages.filter((u) => u !== undefined);
61
+ if (reported.length === 0)
62
+ return undefined;
63
+ const total = emptyTokenUsage();
64
+ for (const usage of reported)
65
+ accumulateTokenUsage(total, usage);
66
+ return total;
67
+ }
68
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,iFAAiF;AACjF,kFAAkF;AAClF,gFAAgF;AAChF,+EAA+E;AAC/E,4BAA4B;AAkC5B,4BAA4B;AAC5B,MAAM,UAAU,eAAe;IAC7B,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;AACrE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAyB,EAAE,MAAuB;IAC1E,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC;IACjC,OAAO,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,CAAC;AAC7D,CAAC;AAED,SAAS,OAAO,CAAC,MAAuB,EAAE,GAAoB;IAC5D,MAAM,CAAC,aAAa,IAAI,GAAG,CAAC,aAAa,CAAC;IAC1C,MAAM,CAAC,iBAAiB,IAAI,GAAG,CAAC,iBAAiB,CAAC;IAClD,MAAM,CAAC,YAAY,IAAI,GAAG,CAAC,YAAY,CAAC;IACxC,IAAI,GAAG,CAAC,mBAAmB,KAAK,SAAS,EAAE,CAAC;QAC1C,MAAM,CAAC,mBAAmB,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EAAE,CAAC;IAChC,KAAK,MAAM,KAAK,IAAI,QAAQ;QAAE,oBAAoB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACjE,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@studio-foundation/contracts",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Shared TypeScript types and interfaces for Studio packages",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
+ "types": "./dist/index.d.ts",
10
11
  "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
12
+ "require": "./dist/index.js"
12
13
  }
13
14
  },
14
15
  "files": [
@@ -1,35 +0,0 @@
1
- export interface IntegrationPluginDef {
2
- name: string;
3
- version: number;
4
- description?: string;
5
- config?: {
6
- required?: string[];
7
- optional?: Record<string, unknown>;
8
- };
9
- events?: {
10
- consumes?: string[];
11
- emits?: string[];
12
- };
13
- test?: {
14
- type: 'http';
15
- endpoint: string;
16
- method?: 'GET' | 'POST';
17
- /** e.g. "bearer:${LINEAR_API_KEY}" — resolved before use */
18
- auth?: string;
19
- body?: string;
20
- expect?: {
21
- status?: number;
22
- };
23
- };
24
- webhook?: {
25
- hmac?: {
26
- header: string;
27
- secret_env: string;
28
- };
29
- handler: string;
30
- };
31
- on_failure?: {
32
- handler: string;
33
- };
34
- }
35
- //# sourceMappingURL=integration-plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"integration-plugin.d.ts","sourceRoot":"","sources":["../src/integration-plugin.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,CAAC;IACF,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;KAClB,CAAC;IACF,IAAI,CAAC,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;QACxB,4DAA4D;QAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE;YAAE,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;KAC9B,CAAC;IACF,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE;YACL,MAAM,EAAE,MAAM,CAAC;YACf,UAAU,EAAE,MAAM,CAAC;SACpB,CAAC;QACF,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,UAAU,CAAC,EAAE;QACX,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH"}
@@ -1,3 +0,0 @@
1
- // contracts/src/integration-plugin.ts
2
- export {};
3
- //# sourceMappingURL=integration-plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"integration-plugin.js","sourceRoot":"","sources":["../src/integration-plugin.ts"],"names":[],"mappings":"AAAA,sCAAsC"}