@graphorin/core 0.5.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 (134) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +21 -0
  3. package/README.md +70 -0
  4. package/dist/channels/channels.d.ts +156 -0
  5. package/dist/channels/channels.d.ts.map +1 -0
  6. package/dist/channels/channels.js +90 -0
  7. package/dist/channels/channels.js.map +1 -0
  8. package/dist/channels/directive.d.ts +34 -0
  9. package/dist/channels/directive.d.ts.map +1 -0
  10. package/dist/channels/directive.js +29 -0
  11. package/dist/channels/directive.js.map +1 -0
  12. package/dist/channels/dispatch.d.ts +26 -0
  13. package/dist/channels/dispatch.d.ts.map +1 -0
  14. package/dist/channels/dispatch.js +32 -0
  15. package/dist/channels/dispatch.js.map +1 -0
  16. package/dist/channels/index.d.ts +5 -0
  17. package/dist/channels/index.js +6 -0
  18. package/dist/channels/pause.d.ts +84 -0
  19. package/dist/channels/pause.d.ts.map +1 -0
  20. package/dist/channels/pause.js +90 -0
  21. package/dist/channels/pause.js.map +1 -0
  22. package/dist/contracts/auth-token-store.d.ts +45 -0
  23. package/dist/contracts/auth-token-store.d.ts.map +1 -0
  24. package/dist/contracts/checkpoint-store.d.ts +90 -0
  25. package/dist/contracts/checkpoint-store.d.ts.map +1 -0
  26. package/dist/contracts/embedder.d.ts +45 -0
  27. package/dist/contracts/embedder.d.ts.map +1 -0
  28. package/dist/contracts/eval-scorer.d.ts +46 -0
  29. package/dist/contracts/eval-scorer.d.ts.map +1 -0
  30. package/dist/contracts/index.d.ts +22 -0
  31. package/dist/contracts/index.js +6 -0
  32. package/dist/contracts/local-provider-trust.d.ts +36 -0
  33. package/dist/contracts/local-provider-trust.d.ts.map +1 -0
  34. package/dist/contracts/logger.d.ts +53 -0
  35. package/dist/contracts/logger.d.ts.map +1 -0
  36. package/dist/contracts/logger.js +21 -0
  37. package/dist/contracts/logger.js.map +1 -0
  38. package/dist/contracts/memory-store.d.ts +106 -0
  39. package/dist/contracts/memory-store.d.ts.map +1 -0
  40. package/dist/contracts/oauth-server-store.d.ts +81 -0
  41. package/dist/contracts/oauth-server-store.d.ts.map +1 -0
  42. package/dist/contracts/preferred-model.d.ts +60 -0
  43. package/dist/contracts/preferred-model.d.ts.map +1 -0
  44. package/dist/contracts/preferred-model.js +15 -0
  45. package/dist/contracts/preferred-model.js.map +1 -0
  46. package/dist/contracts/provider.d.ts +272 -0
  47. package/dist/contracts/provider.d.ts.map +1 -0
  48. package/dist/contracts/reasoning-retention.d.ts +53 -0
  49. package/dist/contracts/reasoning-retention.d.ts.map +1 -0
  50. package/dist/contracts/redaction-validator.d.ts +59 -0
  51. package/dist/contracts/redaction-validator.d.ts.map +1 -0
  52. package/dist/contracts/sandbox.d.ts +73 -0
  53. package/dist/contracts/sandbox.d.ts.map +1 -0
  54. package/dist/contracts/secret-ref.d.ts +26 -0
  55. package/dist/contracts/secret-ref.d.ts.map +1 -0
  56. package/dist/contracts/secret-value.d.ts +112 -0
  57. package/dist/contracts/secret-value.d.ts.map +1 -0
  58. package/dist/contracts/secret-value.js +24 -0
  59. package/dist/contracts/secret-value.js.map +1 -0
  60. package/dist/contracts/secrets-store.d.ts +87 -0
  61. package/dist/contracts/secrets-store.d.ts.map +1 -0
  62. package/dist/contracts/session-store.d.ts +142 -0
  63. package/dist/contracts/session-store.d.ts.map +1 -0
  64. package/dist/contracts/token-counter.d.ts +28 -0
  65. package/dist/contracts/token-counter.d.ts.map +1 -0
  66. package/dist/contracts/tool.d.ts +264 -0
  67. package/dist/contracts/tool.d.ts.map +1 -0
  68. package/dist/contracts/tracer.d.ts +84 -0
  69. package/dist/contracts/tracer.d.ts.map +1 -0
  70. package/dist/contracts/tracer.js +34 -0
  71. package/dist/contracts/tracer.js.map +1 -0
  72. package/dist/contracts/trigger-store.d.ts +43 -0
  73. package/dist/contracts/trigger-store.d.ts.map +1 -0
  74. package/dist/index.d.ts +59 -0
  75. package/dist/index.d.ts.map +1 -0
  76. package/dist/index.js +38 -0
  77. package/dist/index.js.map +1 -0
  78. package/dist/types/agent-event.d.ts +449 -0
  79. package/dist/types/agent-event.d.ts.map +1 -0
  80. package/dist/types/handoff.d.ts +112 -0
  81. package/dist/types/handoff.d.ts.map +1 -0
  82. package/dist/types/index.d.ts +13 -0
  83. package/dist/types/index.js +6 -0
  84. package/dist/types/memory.d.ts +354 -0
  85. package/dist/types/memory.d.ts.map +1 -0
  86. package/dist/types/message.d.ts +162 -0
  87. package/dist/types/message.d.ts.map +1 -0
  88. package/dist/types/run.d.ts +155 -0
  89. package/dist/types/run.d.ts.map +1 -0
  90. package/dist/types/run.js +31 -0
  91. package/dist/types/run.js.map +1 -0
  92. package/dist/types/sensitivity.d.ts +35 -0
  93. package/dist/types/sensitivity.d.ts.map +1 -0
  94. package/dist/types/sensitivity.js +29 -0
  95. package/dist/types/sensitivity.js.map +1 -0
  96. package/dist/types/session-scope.d.ts +22 -0
  97. package/dist/types/session-scope.d.ts.map +1 -0
  98. package/dist/types/stop-condition.d.ts +62 -0
  99. package/dist/types/stop-condition.d.ts.map +1 -0
  100. package/dist/types/stop-condition.js +81 -0
  101. package/dist/types/stop-condition.js.map +1 -0
  102. package/dist/types/tool-call.d.ts +27 -0
  103. package/dist/types/tool-call.d.ts.map +1 -0
  104. package/dist/types/tool.d.ts +260 -0
  105. package/dist/types/tool.d.ts.map +1 -0
  106. package/dist/types/usage.d.ts +82 -0
  107. package/dist/types/usage.d.ts.map +1 -0
  108. package/dist/types/usage.js +17 -0
  109. package/dist/types/usage.js.map +1 -0
  110. package/dist/types/workflow-event.d.ts +108 -0
  111. package/dist/types/workflow-event.d.ts.map +1 -0
  112. package/dist/utils/assert-never.d.ts +26 -0
  113. package/dist/utils/assert-never.d.ts.map +1 -0
  114. package/dist/utils/assert-never.js +29 -0
  115. package/dist/utils/assert-never.js.map +1 -0
  116. package/dist/utils/async-context.d.ts +37 -0
  117. package/dist/utils/async-context.d.ts.map +1 -0
  118. package/dist/utils/async-context.js +33 -0
  119. package/dist/utils/async-context.js.map +1 -0
  120. package/dist/utils/hash.d.ts +30 -0
  121. package/dist/utils/hash.d.ts.map +1 -0
  122. package/dist/utils/hash.js +102 -0
  123. package/dist/utils/hash.js.map +1 -0
  124. package/dist/utils/index.d.ts +6 -0
  125. package/dist/utils/index.js +7 -0
  126. package/dist/utils/streams.d.ts +59 -0
  127. package/dist/utils/streams.d.ts.map +1 -0
  128. package/dist/utils/streams.js +169 -0
  129. package/dist/utils/streams.js.map +1 -0
  130. package/dist/utils/validation.d.ts +67 -0
  131. package/dist/utils/validation.d.ts.map +1 -0
  132. package/dist/utils/validation.js +36 -0
  133. package/dist/utils/validation.js.map +1 -0
  134. package/package.json +82 -0
@@ -0,0 +1,81 @@
1
+ //#region src/contracts/oauth-server-store.d.ts
2
+ /**
3
+ * Persisted metadata for an OAuth server registration. The framework
4
+ * never stores raw token material here — the access, refresh, id, and
5
+ * client-secret tokens live in the {@link SecretsStore} and this
6
+ * record only holds the {@link SecretRef} URIs that resolve them.
7
+ *
8
+ * Schema mirrors the canonical `oauth_servers` SQLite table provided
9
+ * by `@graphorin/store-sqlite`.
10
+ *
11
+ * @stable
12
+ */
13
+ interface OAuthServerRecord {
14
+ /** Stable, human-readable identifier (e.g. `'linear-mcp'`). */
15
+ readonly id: string;
16
+ /** Base URL of the OAuth-protected resource server (e.g. MCP endpoint). */
17
+ readonly serverUrl: string;
18
+ /** Authorization-server `authorization_endpoint`. */
19
+ readonly authorizationEndpoint?: string;
20
+ /** Authorization-server `token_endpoint`. */
21
+ readonly tokenEndpoint?: string;
22
+ /** Authorization-server `registration_endpoint` (RFC 7591). */
23
+ readonly registrationEndpoint?: string;
24
+ /** Authorization-server `revocation_endpoint` (RFC 7009). */
25
+ readonly revocationEndpoint?: string;
26
+ /** Authorization-server `device_authorization_endpoint` (RFC 8628). */
27
+ readonly deviceAuthorizationEndpoint?: string;
28
+ /** Issuer identifier reported in the discovery response. */
29
+ readonly issuer?: string;
30
+ /** Public client identifier; safe to log. */
31
+ readonly clientId: string;
32
+ /** {@link SecretRef} URI for the confidential-client secret. */
33
+ readonly clientSecretRef?: string;
34
+ /** {@link SecretRef} URI for the access token. */
35
+ readonly accessTokenRef?: string;
36
+ /** {@link SecretRef} URI for the refresh token. */
37
+ readonly refreshTokenRef?: string;
38
+ /** {@link SecretRef} URI for the OIDC ID token. */
39
+ readonly idTokenRef?: string;
40
+ /** Epoch milliseconds when the access token stops being valid. */
41
+ readonly expiresAt?: number;
42
+ /** Granted scopes (space-separated string per the OAuth spec). */
43
+ readonly scope?: string;
44
+ /** Redirect URI that was used during the most recent code flow. */
45
+ readonly redirectUri?: string;
46
+ /** Whether the client was registered via Dynamic Client Registration. */
47
+ readonly registeredVia?: 'dcr' | 'manual';
48
+ /** Epoch milliseconds of the last successful refresh. */
49
+ readonly lastRefreshedAt?: number;
50
+ /** Last error string captured from a failing refresh attempt. */
51
+ readonly lastRefreshError?: string;
52
+ /** Epoch milliseconds when the record was first created. */
53
+ readonly createdAt: number;
54
+ /** Epoch milliseconds when the record was last updated. */
55
+ readonly updatedAt: number;
56
+ }
57
+ /**
58
+ * Pluggable storage for OAuth server registrations + token metadata.
59
+ *
60
+ * The default implementation lives in `@graphorin/store-sqlite`
61
+ * (`oauth_servers` table). `@graphorin/security` ships an in-memory
62
+ * implementation that callers can use until the SQLite-backed store
63
+ * is wired up.
64
+ *
65
+ * @stable
66
+ */
67
+ interface OAuthServerStore {
68
+ /** Insert or replace the record for `id`. */
69
+ put(record: OAuthServerRecord): Promise<void>;
70
+ /** Read the record for `id`, returning `null` when absent. */
71
+ get(id: string): Promise<OAuthServerRecord | null>;
72
+ /** Snapshot of all stored records, ordered by `id`. */
73
+ list(): Promise<ReadonlyArray<OAuthServerRecord>>;
74
+ /** Apply a partial update to the record at `id`. */
75
+ update(id: string, patch: Partial<OAuthServerRecord>): Promise<OAuthServerRecord>;
76
+ /** Remove the record for `id`. */
77
+ delete(id: string): Promise<void>;
78
+ }
79
+ //#endregion
80
+ export { OAuthServerRecord, OAuthServerStore };
81
+ //# sourceMappingURL=oauth-server-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-server-store.d.ts","names":[],"sources":["../../src/contracts/oauth-server-store.ts"],"sourcesContent":[],"mappings":";;AAWA;AAuDA;;;;;;;;;AAQ4B,UA/DX,iBAAA,CA+DW;EAAqC;EAAR,SAAA,EAAA,EAAA,MAAA;EAEnC;EAAO,SAAA,SAAA,EAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAVZ,gBAAA;;cAEH,oBAAoB;;mBAEf,QAAQ;;UAEjB,QAAQ,cAAc;;4BAEJ,QAAQ,qBAAqB,QAAQ;;sBAE3C"}
@@ -0,0 +1,60 @@
1
+ //#region src/contracts/preferred-model.d.ts
2
+ /**
3
+ * Cost-tier vocabulary for declaring a preferred model on a tool or
4
+ * agent. Provider-agnostic at the tool-author level; the operator-side
5
+ * `Agent.modelTierMap?: Partial<Record<ModelHint, ModelSpec>>` mapping
6
+ * resolves the hint to a concrete provider per agent.
7
+ *
8
+ * The three tiers describe canonical cloud-provider price-quality
9
+ * envelopes circa 2026:
10
+ *
11
+ * - `'fast'` — low-cost / low-latency / file-navigation /
12
+ * parameter-extraction / low-stakes calls.
13
+ * - `'balanced'` — median cost-quality; the default tier for most
14
+ * tools.
15
+ * - `'smart'` — high-quality / high-stakes / reasoning-heavy /
16
+ * summarization / code-review calls.
17
+ *
18
+ * The vocabulary is Graphorin's own design — no third-party routing-
19
+ * guide attribution leaks into the public surface. Per-provider
20
+ * dispatch lives in `@graphorin/provider/model-tier/classify.ts`.
21
+ *
22
+ * @stable
23
+ */
24
+ type ModelHint = 'fast' | 'balanced' | 'smart';
25
+ /**
26
+ * Discriminated string-literal triple for type-level work.
27
+ *
28
+ * @stable
29
+ */
30
+ declare const MODEL_HINTS: readonly ModelHint[];
31
+ /**
32
+ * Forward-declared shape of `Provider`. Re-declared here as a minimal
33
+ * structural type so this module stays cycle-free with respect to
34
+ * `./provider.ts` and downstream consumers can use `ModelSpec` without
35
+ * importing the heavier `Provider` interface.
36
+ *
37
+ * @internal
38
+ */
39
+ interface ProviderLike {
40
+ readonly name: string;
41
+ readonly modelId: string;
42
+ }
43
+ /**
44
+ * Concrete provider declaration used at site of the per-tool hint
45
+ * override (Phase 07), the per-tier mapping
46
+ * (`Agent.modelTierMap`, Phase 12), and the agent-level fallback chain
47
+ * (`Agent.fallbackModels`, Phase 12).
48
+ *
49
+ * The shape is unified deliberately so operators learn one thing and
50
+ * use it three places.
51
+ *
52
+ * @stable
53
+ */
54
+ type ModelSpec = ProviderLike | {
55
+ readonly provider: ProviderLike;
56
+ readonly model: string;
57
+ };
58
+ //#endregion
59
+ export { MODEL_HINTS, ModelHint, ModelSpec, ProviderLike };
60
+ //# sourceMappingURL=preferred-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preferred-model.d.ts","names":[],"sources":["../../src/contracts/preferred-model.ts"],"sourcesContent":[],"mappings":";;AAsBA;AAOA;AAUA;AAgBA;;;;;;;;;;;;;;;;;;KAjCY,SAAA;;;;;;cAOC,sBAAsB;;;;;;;;;UAUlB,YAAA;;;;;;;;;;;;;;;KAgBL,SAAA,GAAY;qBAAoC"}
@@ -0,0 +1,15 @@
1
+ //#region src/contracts/preferred-model.ts
2
+ /**
3
+ * Discriminated string-literal triple for type-level work.
4
+ *
5
+ * @stable
6
+ */
7
+ const MODEL_HINTS = [
8
+ "fast",
9
+ "balanced",
10
+ "smart"
11
+ ];
12
+
13
+ //#endregion
14
+ export { MODEL_HINTS };
15
+ //# sourceMappingURL=preferred-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preferred-model.js","names":["MODEL_HINTS: readonly ModelHint[]"],"sources":["../../src/contracts/preferred-model.ts"],"sourcesContent":["/**\n * Cost-tier vocabulary for declaring a preferred model on a tool or\n * agent. Provider-agnostic at the tool-author level; the operator-side\n * `Agent.modelTierMap?: Partial<Record<ModelHint, ModelSpec>>` mapping\n * resolves the hint to a concrete provider per agent.\n *\n * The three tiers describe canonical cloud-provider price-quality\n * envelopes circa 2026:\n *\n * - `'fast'` — low-cost / low-latency / file-navigation /\n * parameter-extraction / low-stakes calls.\n * - `'balanced'` — median cost-quality; the default tier for most\n * tools.\n * - `'smart'` — high-quality / high-stakes / reasoning-heavy /\n * summarization / code-review calls.\n *\n * The vocabulary is Graphorin's own design — no third-party routing-\n * guide attribution leaks into the public surface. Per-provider\n * dispatch lives in `@graphorin/provider/model-tier/classify.ts`.\n *\n * @stable\n */\nexport type ModelHint = 'fast' | 'balanced' | 'smart';\n\n/**\n * Discriminated string-literal triple for type-level work.\n *\n * @stable\n */\nexport const MODEL_HINTS: readonly ModelHint[] = ['fast', 'balanced', 'smart'] as const;\n\n/**\n * Forward-declared shape of `Provider`. Re-declared here as a minimal\n * structural type so this module stays cycle-free with respect to\n * `./provider.ts` and downstream consumers can use `ModelSpec` without\n * importing the heavier `Provider` interface.\n *\n * @internal\n */\nexport interface ProviderLike {\n readonly name: string;\n readonly modelId: string;\n}\n\n/**\n * Concrete provider declaration used at site of the per-tool hint\n * override (Phase 07), the per-tier mapping\n * (`Agent.modelTierMap`, Phase 12), and the agent-level fallback chain\n * (`Agent.fallbackModels`, Phase 12).\n *\n * The shape is unified deliberately so operators learn one thing and\n * use it three places.\n *\n * @stable\n */\nexport type ModelSpec = ProviderLike | { readonly provider: ProviderLike; readonly model: string };\n"],"mappings":";;;;;;AA6BA,MAAaA,cAAoC;CAAC;CAAQ;CAAY;CAAQ"}
@@ -0,0 +1,272 @@
1
+ import { Sensitivity } from "../types/sensitivity.js";
2
+ import { Message } from "../types/message.js";
3
+ import { Usage } from "../types/usage.js";
4
+ import { ReasoningContract, ReasoningRetention } from "./reasoning-retention.js";
5
+
6
+ //#region src/contracts/provider.d.ts
7
+
8
+ /**
9
+ * Vendor-neutral LLM provider interface. Concrete adapters live in
10
+ * `@graphorin/provider` (and companion packages such as
11
+ * `@graphorin/provider-llamacpp-node`).
12
+ *
13
+ * Every provider exposes a `name` (used in spans / logs), the `modelId`
14
+ * it wraps, a static `capabilities` descriptor, and the two streaming /
15
+ * one-shot generation methods.
16
+ *
17
+ * @stable
18
+ */
19
+ interface Provider {
20
+ readonly name: string;
21
+ readonly modelId: string;
22
+ readonly capabilities: ProviderCapabilities;
23
+ /** Returns an async stream of fine-grained provider events. */
24
+ stream(req: ProviderRequest): AsyncIterable<ProviderEvent>;
25
+ /** Convenience wrapper that consumes the stream into a single result. */
26
+ generate(req: ProviderRequest): Promise<ProviderResponse>;
27
+ /** Optional: provider-native input token counter. */
28
+ countTokens?(req: ProviderRequest): Promise<number>;
29
+ /**
30
+ * Sensitivity tiers this provider is allowed to receive. Used by the
31
+ * ContextEngine sensitivity filter (D2) and the outbound redaction
32
+ * middleware (D3) to decide what content is safe to forward.
33
+ */
34
+ readonly acceptsSensitivity?: ReadonlyArray<Sensitivity>;
35
+ }
36
+ /**
37
+ * Static capability descriptor returned by `Provider.capabilities`.
38
+ *
39
+ * @stable
40
+ */
41
+ interface ProviderCapabilities {
42
+ readonly streaming: boolean;
43
+ readonly toolCalling: boolean;
44
+ readonly parallelToolCalls: boolean;
45
+ readonly multimodal: boolean;
46
+ readonly structuredOutput: boolean;
47
+ readonly reasoning: boolean;
48
+ /** Total context window in tokens. */
49
+ readonly contextWindow: number;
50
+ /** Maximum output tokens. */
51
+ readonly maxOutput: number;
52
+ /**
53
+ * How the provider treats reasoning content across consecutive
54
+ * `provider.stream(...)` calls. Drives the auto-detected default
55
+ * {@link ReasoningRetention} value when the caller does not pass
56
+ * an explicit override on the request.
57
+ *
58
+ * Adapters supplied with the framework declare this field; bespoke
59
+ * adapters that omit it are treated as `'optional'` (conservative
60
+ * `'strip'` default + WARN-once on first reasoning emission).
61
+ */
62
+ readonly reasoningContract?: ReasoningContract;
63
+ }
64
+ /**
65
+ * Provider-call request payload.
66
+ *
67
+ * @stable
68
+ */
69
+ interface ProviderRequest {
70
+ readonly messages: ReadonlyArray<Message>;
71
+ readonly tools?: ReadonlyArray<ToolDefinition>;
72
+ readonly toolChoice?: ToolChoice;
73
+ readonly outputType?: OutputSpec;
74
+ readonly systemMessage?: string;
75
+ readonly temperature?: number;
76
+ readonly maxTokens?: number;
77
+ readonly signal?: AbortSignal;
78
+ readonly providerOptions?: Readonly<Record<string, unknown>>;
79
+ readonly metadata?: ProviderRequestMetadata;
80
+ /**
81
+ * Per-request override of the provider's auto-detected
82
+ * {@link ReasoningRetention} default. Only honoured when the
83
+ * provider declares `reasoningContract` of `'round-trip-required'`
84
+ * or `'optional'`; hidden-chain-of-thought providers (e.g.
85
+ * `'hidden'`) always strip and emit one WARN per process when an
86
+ * incompatible override is supplied.
87
+ */
88
+ readonly reasoningRetention?: ReasoningRetention;
89
+ }
90
+ /**
91
+ * Per-request metadata used by tracing and auditing layers.
92
+ *
93
+ * @stable
94
+ */
95
+ interface ProviderRequestMetadata {
96
+ readonly sessionId?: string;
97
+ readonly agentId?: string;
98
+ readonly userId?: string;
99
+ readonly runId?: string;
100
+ readonly stepNumber?: number;
101
+ }
102
+ /**
103
+ * One-shot response shape returned by `Provider.generate(...)`.
104
+ *
105
+ * @stable
106
+ */
107
+ interface ProviderResponse {
108
+ readonly text?: string;
109
+ readonly toolCalls?: ReadonlyArray<{
110
+ readonly toolCallId: string;
111
+ readonly toolName: string;
112
+ readonly args: unknown;
113
+ }>;
114
+ readonly usage: Usage;
115
+ readonly finishReason: FinishReason;
116
+ readonly providerMetadata?: Readonly<Record<string, unknown>>;
117
+ }
118
+ /**
119
+ * Reason a provider call ended.
120
+ *
121
+ * @stable
122
+ */
123
+ type FinishReason = 'stop' | 'length' | 'tool-calls' | 'content-filter' | 'error' | 'aborted';
124
+ /**
125
+ * Streamed provider event. Shape matches the wire-stable subset of the
126
+ * provider event union — adapters hide vendor specifics.
127
+ *
128
+ * @stable
129
+ */
130
+ type ProviderEvent = {
131
+ readonly type: 'stream-start';
132
+ readonly metadata: ResponseMetadata;
133
+ } | {
134
+ readonly type: 'reasoning-delta';
135
+ readonly delta: string;
136
+ } | {
137
+ readonly type: 'text-delta';
138
+ readonly delta: string;
139
+ } | {
140
+ readonly type: 'tool-call-start';
141
+ readonly toolCallId: string;
142
+ readonly toolName: string;
143
+ } | {
144
+ readonly type: 'tool-call-input-delta';
145
+ readonly toolCallId: string;
146
+ readonly argsDelta: string;
147
+ } | {
148
+ readonly type: 'tool-call-end';
149
+ readonly toolCallId: string;
150
+ readonly finalArgs: unknown;
151
+ } | {
152
+ readonly type: 'file';
153
+ readonly mimeType: string;
154
+ readonly data: Uint8Array;
155
+ } | {
156
+ readonly type: 'source';
157
+ readonly uri: string;
158
+ readonly title?: string;
159
+ } | {
160
+ readonly type: 'finish';
161
+ readonly finishReason: FinishReason;
162
+ readonly usage: Usage;
163
+ } | {
164
+ readonly type: 'error';
165
+ readonly error: ProviderError;
166
+ };
167
+ /**
168
+ * Metadata attached to the first `stream-start` event of a stream.
169
+ *
170
+ * @stable
171
+ */
172
+ interface ResponseMetadata {
173
+ readonly providerName: string;
174
+ readonly modelId: string;
175
+ readonly responseId?: string;
176
+ readonly createdAt?: string;
177
+ }
178
+ /**
179
+ * Provider-side error shape carried by `provider-error` events.
180
+ *
181
+ * @stable
182
+ */
183
+ interface ProviderError {
184
+ readonly kind: ProviderErrorKind;
185
+ readonly message: string;
186
+ readonly cause?: unknown;
187
+ }
188
+ /** @stable */
189
+ type ProviderErrorKind = 'rate-limit' | 'capacity' | 'context-length' | 'transient' | 'invalid-request' | 'unauthorized' | 'content-filter' | 'unknown';
190
+ /**
191
+ * Tool description shipped with a provider request. Implementations
192
+ * convert the user's Zod schema to a JSON Schema 7 fragment.
193
+ *
194
+ * @stable
195
+ */
196
+ interface ToolDefinition {
197
+ readonly name: string;
198
+ readonly description?: string;
199
+ readonly inputSchema: Readonly<Record<string, unknown>>;
200
+ /**
201
+ * A5: the tool's output schema (JSON Schema), when declared. The agent runtime
202
+ * populates it from `Tool.outputSchema`; structured-output providers and typed
203
+ * code-mode use it to validate / type the tool's result. Absent when the tool
204
+ * declares no output schema.
205
+ */
206
+ readonly outputSchema?: Readonly<Record<string, unknown>>;
207
+ /**
208
+ * Worked examples surfaced to the provider alongside the schema. The
209
+ * agent runtime populates this from the tool's `examples` when they
210
+ * are eagerly rendered (see `Tool.examplesEagerlyRendered`); it is
211
+ * bounded to ≤5 and absent when the tool declares none or defers them.
212
+ * Implementations MAY fold these into the model-facing tool description.
213
+ */
214
+ readonly examples?: ReadonlyArray<ToolDefinitionExample>;
215
+ }
216
+ /**
217
+ * A single worked example as projected onto the provider wire contract —
218
+ * a serializable, schema-agnostic view of a `ToolExample`. `input` /
219
+ * `output` carry the example's already-parsed values; `comment` is the
220
+ * optional rationale shown to the model.
221
+ *
222
+ * @stable
223
+ */
224
+ interface ToolDefinitionExample {
225
+ readonly input: unknown;
226
+ readonly output: unknown;
227
+ readonly comment?: string;
228
+ }
229
+ /**
230
+ * Tool selection strategy.
231
+ *
232
+ * @stable
233
+ */
234
+ type ToolChoice = 'auto' | 'required' | 'none' | {
235
+ readonly tool: string;
236
+ };
237
+ /**
238
+ * Output type specification for structured / typed responses. Concrete
239
+ * Zod-based variants live in the runtime packages.
240
+ *
241
+ * @stable
242
+ */
243
+ interface OutputSpec {
244
+ readonly kind: 'text' | 'structured';
245
+ readonly description?: string;
246
+ readonly jsonSchema?: Readonly<Record<string, unknown>>;
247
+ }
248
+ /**
249
+ * Provider middleware: a function that wraps a `Provider` and returns a
250
+ * new `Provider` with extra behaviour (retry, fallback, redaction, …).
251
+ *
252
+ * Middleware ordering is enforced by the runtime per the documented
253
+ * inside-out chain (innermost adapter → ... → outermost retry / observer).
254
+ *
255
+ * @stable
256
+ */
257
+ type ProviderMiddleware = (next: Provider) => Provider;
258
+ /**
259
+ * Type signature for the canonical middleware composer (the runtime
260
+ * implementation lives in `@graphorin/provider`).
261
+ *
262
+ * The concrete composer guarantees a deterministic ordering — order of
263
+ * arguments mirrors order of execution from outermost to innermost — and
264
+ * is the only blessed entry point for chaining middleware in
265
+ * `@graphorin/*` code (per the security-first ordering rule).
266
+ *
267
+ * @stable
268
+ */
269
+ type ComposeProviderMiddleware = (middlewares: ReadonlyArray<ProviderMiddleware>) => ProviderMiddleware;
270
+ //#endregion
271
+ export { ComposeProviderMiddleware, FinishReason, OutputSpec, Provider, ProviderCapabilities, ProviderError, ProviderErrorKind, ProviderEvent, ProviderMiddleware, ProviderRequest, ProviderRequestMetadata, ProviderResponse, ResponseMetadata, ToolChoice, ToolDefinition, ToolDefinitionExample };
272
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","names":[],"sources":["../../src/contracts/provider.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAgBA;;;;;;;;;AAYsC,UAZrB,QAAA,CAYqB;EAOQ,SAAA,IAAA,EAAA,MAAA;EAAd,SAAA,OAAA,EAAA,MAAA;EAAa,SAAA,YAAA,EAhBpB,oBAgBoB;EAQ5B;EA6BA,MAAA,CAAA,GAAA,EAlDH,eAkDkB,CAAA,EAlDA,aAkDA,CAlDc,aAkDd,CAAA;EACG;EAAd,QAAA,CAAA,GAAA,EAhDL,eAgDK,CAAA,EAhDa,OAgDb,CAhDqB,gBAgDrB,CAAA;EACY;EAAd,WAAA,EAAA,GAAA,EA9CC,eA8CD,CAAA,EA9CmB,OA8CnB,CAAA,MAAA,CAAA;EACK;;;;;EAOF,SAAA,kBAAA,CAAA,EA/CU,aA+CV,CA/CwB,WA+CxB,CAAA;;;AAiBtB;AAaA;;;AAQyB,UA7ER,oBAAA,CA6EQ;EACc,SAAA,SAAA,EAAA,OAAA;EAAT,SAAA,WAAA,EAAA,OAAA;EAAQ,SAAA,iBAAA,EAAA,OAAA;EAQ1B,SAAA,UAAY,EAAA,OAAA;EAcZ,SAAA,gBAAa,EAAA,OAAA;EAC+B,SAAA,SAAA,EAAA,OAAA;EAUe;EAEjB,SAAA,aAAA,EAAA,MAAA;EAA8B;EACtC,SAAA,SAAA,EAAA,MAAA;EAAa;AAO3D;AAYA;AAOA;AAgBA;;;;;;EAkBsB,SAAA,iBAAA,CAAA,EAzJS,iBAyJT;;AAWtB;AAWA;AAQA;AAeA;AAaA;AAC6B,UA5MZ,eAAA,CA4MY;EAAd,SAAA,QAAA,EA3MM,aA2MN,CA3MoB,OA2MpB,CAAA;EACV,SAAA,KAAA,CAAA,EA3Mc,aA2Md,CA3M4B,cA2M5B,CAAA;EAAkB,SAAA,UAAA,CAAA,EA1MC,UA0MD;wBAzMC;;;;oBAIJ;6BACS,SAAS;sBAChB;;;;;;;;;gCASU;;;;;;;UAQf,uBAAA;;;;;;;;;;;;UAaA,gBAAA;;uBAEM;;;;;kBAKL;yBACO;8BACK,SAAS;;;;;;;KAQ3B,YAAA;;;;;;;KAcA,aAAA;;qBAC4C;;;;;;;;;;;;;;;;;;;;;;iBAUe;;;;;;;yBAEjB;kBAA8B;;;kBACtC;;;;;;;UAO7B,gBAAA;;;;;;;;;;;UAYA,aAAA;iBACA;;;;;KAML,iBAAA;;;;;;;UAgBK,cAAA;;;wBAGO,SAAS;;;;;;;0BAOP,SAAS;;;;;;;;sBAQb,cAAc;;;;;;;;;;UAWnB,qBAAA;;;;;;;;;;KAWL,UAAA;;;;;;;;;UAQK,UAAA;;;wBAGO,SAAS;;;;;;;;;;;KAYrB,kBAAA,UAA4B,aAAa;;;;;;;;;;;;KAazC,yBAAA,iBACG,cAAc,wBACxB"}
@@ -0,0 +1,53 @@
1
+ //#region src/contracts/reasoning-retention.d.ts
2
+ /**
3
+ * How a provider treats reasoning content across consecutive
4
+ * `provider.stream(...)` calls of the same agent + same model + same
5
+ * run.
6
+ *
7
+ * Three independent lifecycle operations exist for reasoning content
8
+ * in the provider layer:
9
+ *
10
+ * 1. **Intra-loop transmission** — controlled by this enum. Default is
11
+ * auto-detected per provider:
12
+ * - Hidden chain-of-thought providers (e.g. OpenAI o1/o3, Google
13
+ * Gemini reasoning): `'strip'`.
14
+ * - Round-trip-required providers (e.g. Anthropic Claude tool-use
15
+ * with thinking blocks): `'pass-through-claude'`.
16
+ * 2. **Sub-agent handoff transmission** — always strips reasoning
17
+ * regardless of this setting; lives in
18
+ * `@graphorin/sessions` handoff filters.
19
+ * 3. **Prompt-cache key calculation** — reasoning blocks are excluded
20
+ * from cache-key hashes but included in outbound transmission.
21
+ *
22
+ * @stable
23
+ */
24
+ type ReasoningRetention =
25
+ /**
26
+ * Drop reasoning content from the next request body. Default for
27
+ * hidden-chain-of-thought providers and the conservative default
28
+ * for unknown providers.
29
+ */
30
+ 'strip'
31
+ /**
32
+ * Round-trip Anthropic-shaped thinking blocks
33
+ * (`signature` / `data` / `text` fields) byte-equal to the previous
34
+ * assistant message.
35
+ */ | 'pass-through-claude'
36
+ /**
37
+ * Round-trip every reasoning content part the provider returns
38
+ * regardless of vendor shape. Useful for custom providers that
39
+ * declare `reasoningContract: 'optional'` and still benefit from
40
+ * preserving the chain.
41
+ */ | 'pass-through-all';
42
+ /**
43
+ * Capability declaration on `ProviderCapabilities` describing how the
44
+ * provider treats reasoning content. The field is auto-populated per
45
+ * provider family by the adapter; consumers use it to infer the
46
+ * default {@link ReasoningRetention} value for a request.
47
+ *
48
+ * @stable
49
+ */
50
+ type ReasoningContract = 'hidden' | 'round-trip-required' | 'optional';
51
+ //#endregion
52
+ export { ReasoningContract, ReasoningRetention };
53
+ //# sourceMappingURL=reasoning-retention.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reasoning-retention.d.ts","names":[],"sources":["../../src/contracts/reasoning-retention.ts"],"sourcesContent":[],"mappings":";;AAsBA;AA6BA;;;;;;;;;;;;;;;;;;;;KA7BY,kBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;KA6BA,iBAAA"}
@@ -0,0 +1,59 @@
1
+ import { Sensitivity } from "../types/sensitivity.js";
2
+
3
+ //#region src/contracts/redaction-validator.d.ts
4
+
5
+ /**
6
+ * Wraps every observability exporter (OTLP, console, JSONL replay log,
7
+ * …) and refuses to forward attributes that exceed the configured
8
+ * sensitivity floor or that contain matched secret / PII patterns.
9
+ *
10
+ * Concrete patterns and the default policy live in
11
+ * `@graphorin/observability`; the interface lives here so every package
12
+ * (server, agent, workflow, …) can require a `RedactionValidator` in its
13
+ * config without taking an observability dependency.
14
+ *
15
+ * @stable
16
+ */
17
+ interface RedactionValidator {
18
+ /** Identifier of the policy in use (`'default-deny-internal'`, …). */
19
+ readonly id: string;
20
+ /** Lowest tier that may pass through the validator. */
21
+ readonly minTier: Sensitivity;
22
+ /**
23
+ * Validate (and optionally rewrite) an attribute payload. Returns the
24
+ * sanitized value or `null` if the entire record must be dropped.
25
+ */
26
+ validate(input: RedactionInput): RedactionOutput | null;
27
+ }
28
+ /**
29
+ * Input handed to `RedactionValidator.validate(...)`.
30
+ *
31
+ * @stable
32
+ */
33
+ interface RedactionInput {
34
+ readonly value: unknown;
35
+ /** Tier declared by the upstream caller for this value. */
36
+ readonly tier: Sensitivity;
37
+ /** Optional context describing where the value originated. */
38
+ readonly context?: {
39
+ readonly attribute?: string;
40
+ readonly spanType?: string;
41
+ readonly origin?: string;
42
+ };
43
+ }
44
+ /**
45
+ * Result of `RedactionValidator.validate(...)` — either the sanitized
46
+ * payload (possibly equal to the input) or `null` if the value must be
47
+ * dropped entirely.
48
+ *
49
+ * @stable
50
+ */
51
+ interface RedactionOutput {
52
+ readonly value: unknown;
53
+ readonly tier: Sensitivity;
54
+ /** List of pattern names matched while validating. */
55
+ readonly matched?: ReadonlyArray<string>;
56
+ }
57
+ //#endregion
58
+ export { RedactionInput, RedactionOutput, RedactionValidator };
59
+ //# sourceMappingURL=redaction-validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redaction-validator.d.ts","names":[],"sources":["../../src/contracts/redaction-validator.ts"],"sourcesContent":[],"mappings":";;;;;;AAcA;;;;;AAiBA;AAmBA;;;;UApCiB,kBAAA;;;;oBAIG;;;;;kBAKF,iBAAiB;;;;;;;UAQlB,cAAA;;;iBAGA;;;;;;;;;;;;;;;UAgBA,eAAA;;iBAEA;;qBAEI"}
@@ -0,0 +1,73 @@
1
+ //#region src/contracts/sandbox.d.ts
2
+ /**
3
+ * Pluggable sandbox interface for tool / skill execution. Concrete
4
+ * implementations live in `@graphorin/security` (worker-threads,
5
+ * isolated-vm, docker, none).
6
+ *
7
+ * @stable
8
+ */
9
+ interface Sandbox {
10
+ /** Identifier of the sandbox flavor (`'worker-threads'`, `'isolated-vm'`, …). */
11
+ readonly id: string;
12
+ run<TInput, TOutput>(code: SandboxCode, opts: SandboxRunOptions<TInput>): Promise<SandboxResult<TOutput>>;
13
+ }
14
+ /**
15
+ * Description of the code to run in the sandbox. Either a JS source
16
+ * string, a path to a JS file, or a fully-qualified handler reference
17
+ * resolved by the sandbox implementation.
18
+ *
19
+ * @stable
20
+ */
21
+ type SandboxCode = {
22
+ readonly kind: 'source';
23
+ readonly source: string;
24
+ readonly filename?: string;
25
+ } | {
26
+ readonly kind: 'file';
27
+ readonly path: string;
28
+ } | {
29
+ readonly kind: 'handler';
30
+ readonly module: string;
31
+ readonly export: string;
32
+ };
33
+ /**
34
+ * Per-call sandbox options.
35
+ *
36
+ * @stable
37
+ */
38
+ interface SandboxRunOptions<TInput = unknown> {
39
+ readonly input: TInput;
40
+ readonly timeoutMs?: number;
41
+ readonly maxMemoryMb?: number;
42
+ /**
43
+ * Allowlist of environment variables visible inside the sandbox.
44
+ * Sandboxed code never inherits the host `process.env`; entries
45
+ * given here are the only ones defined.
46
+ */
47
+ readonly env?: Readonly<Record<string, string>>;
48
+ readonly allowNetwork?: boolean;
49
+ readonly allowFs?: boolean;
50
+ readonly signal?: AbortSignal;
51
+ }
52
+ /**
53
+ * Result of a sandboxed run. The shape mirrors the `ToolOutcome` union —
54
+ * the runtime maps `SandboxResult` to `ToolOutcome` after the call.
55
+ *
56
+ * @stable
57
+ */
58
+ type SandboxResult<TOutput = unknown> = {
59
+ readonly ok: true;
60
+ readonly output: TOutput;
61
+ readonly durationMs: number;
62
+ } | {
63
+ readonly ok: false;
64
+ readonly error: {
65
+ readonly kind: 'timeout' | 'memory-exceeded' | 'sandbox-violation' | 'aborted' | 'execution-failed';
66
+ readonly message: string;
67
+ readonly cause?: unknown;
68
+ };
69
+ readonly durationMs: number;
70
+ };
71
+ //#endregion
72
+ export { Sandbox, SandboxCode, SandboxResult, SandboxRunOptions };
73
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","names":[],"sources":["../../src/contracts/sandbox.ts"],"sourcesContent":[],"mappings":";;AAOA;;;;;;AAMK,UANY,OAAA,CAMZ;EAAO;EAUA,SAAA,EAAA,EAAA,MAAW;EAUN,GAAA,CAAA,MAAA,EAAA,OAAA,CAAiB,CAAA,IAAA,EAtBxB,WAsBwB,EAAA,IAAA,EArBxB,iBAqBwB,CArBN,MAqBM,CAAA,CAAA,EApB7B,OAoB6B,CApBrB,aAoBqB,CApBP,OAoBO,CAAA,CAAA;;;;;;AAqBlC;;;KA/BY,WAAA;;;;;;;;;;;;;;;;;UAUK;kBACC;;;;;;;;iBAQD,SAAS;;;oBAGN;;;;;;;;KASR;;mBAC8B"}
@@ -0,0 +1,26 @@
1
+ //#region src/contracts/secret-ref.d.ts
2
+ /**
3
+ * Parsed shape of a `SecretRef` URI (`scheme:[//authority]/path[?query][#fragment]`).
4
+ *
5
+ * The full grammar lives in `@graphorin/security`; the type lives here so
6
+ * downstream packages can carry parsed refs without a security dependency.
7
+ *
8
+ * @stable
9
+ */
10
+ interface SecretRef {
11
+ /** Original URI string as supplied by the caller. */
12
+ readonly raw: string;
13
+ /** Lowercased scheme (`'env'`, `'keyring'`, `'file'`, …). */
14
+ readonly scheme: string;
15
+ /** Optional authority component (e.g. `host[:port]`). */
16
+ readonly authority?: string;
17
+ /** Path component (without the leading slash for opaque schemes). */
18
+ readonly path: string;
19
+ /** Parsed query parameters (already percent-decoded). */
20
+ readonly query: Readonly<Record<string, string>>;
21
+ /** Optional fragment (e.g. JSON-Pointer for nested fields). */
22
+ readonly fragment?: string;
23
+ }
24
+ //#endregion
25
+ export { SecretRef };
26
+ //# sourceMappingURL=secret-ref.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secret-ref.d.ts","names":[],"sources":["../../src/contracts/secret-ref.ts"],"sourcesContent":[],"mappings":";;AAQA;;;;;;;UAAiB,SAAA;;;;;;;;;;kBAUC,SAAS"}