@agentick/core 0.0.1 → 0.1.9
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/dist/.tsbuildinfo.build +1 -1
- package/package.json +8 -3
- package/dist/.tsbuildinfo +0 -1
- package/dist/agent.d.ts +0 -32
- package/dist/agent.d.ts.map +0 -1
- package/dist/agent.js +0 -26
- package/dist/agent.js.map +0 -1
- package/dist/aidk-instance.d.ts +0 -294
- package/dist/aidk-instance.d.ts.map +0 -1
- package/dist/aidk-instance.js +0 -340
- package/dist/aidk-instance.js.map +0 -1
- package/dist/compiler/content-block-registry.d.ts +0 -11
- package/dist/compiler/content-block-registry.d.ts.map +0 -1
- package/dist/compiler/content-block-registry.js +0 -312
- package/dist/compiler/content-block-registry.js.map +0 -1
- package/dist/compiler/extractors.d.ts +0 -68
- package/dist/compiler/extractors.d.ts.map +0 -1
- package/dist/compiler/extractors.js +0 -547
- package/dist/compiler/extractors.js.map +0 -1
- package/dist/compiler/fiber.d.ts +0 -61
- package/dist/compiler/fiber.d.ts.map +0 -1
- package/dist/compiler/fiber.js +0 -244
- package/dist/compiler/fiber.js.map +0 -1
- package/dist/component/tentickle-component.d.ts +0 -185
- package/dist/component/tentickle-component.d.ts.map +0 -1
- package/dist/component/tentickle-component.js +0 -182
- package/dist/component/tentickle-component.js.map +0 -1
- package/dist/core/channel-helpers.d.ts +0 -31
- package/dist/core/channel-helpers.d.ts.map +0 -1
- package/dist/core/channel-helpers.js +0 -62
- package/dist/core/channel-helpers.js.map +0 -1
- package/dist/core/channel.d.ts +0 -164
- package/dist/core/channel.d.ts.map +0 -1
- package/dist/core/channel.js +0 -199
- package/dist/core/channel.js.map +0 -1
- package/dist/core/context.d.ts +0 -412
- package/dist/core/context.d.ts.map +0 -1
- package/dist/core/context.js +0 -290
- package/dist/core/context.js.map +0 -1
- package/dist/core/event-buffer.d.ts +0 -212
- package/dist/core/event-buffer.d.ts.map +0 -1
- package/dist/core/event-buffer.js +0 -346
- package/dist/core/event-buffer.js.map +0 -1
- package/dist/core/execution-helpers.d.ts +0 -179
- package/dist/core/execution-helpers.d.ts.map +0 -1
- package/dist/core/execution-helpers.js +0 -212
- package/dist/core/execution-helpers.js.map +0 -1
- package/dist/core/execution-tracker.d.ts +0 -53
- package/dist/core/execution-tracker.d.ts.map +0 -1
- package/dist/core/execution-tracker.js +0 -309
- package/dist/core/execution-tracker.js.map +0 -1
- package/dist/core/index.d.ts +0 -58
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -58
- package/dist/core/index.js.map +0 -1
- package/dist/core/logger.d.ts +0 -341
- package/dist/core/logger.d.ts.map +0 -1
- package/dist/core/logger.js +0 -346
- package/dist/core/logger.js.map +0 -1
- package/dist/core/metrics-helpers.d.ts +0 -40
- package/dist/core/metrics-helpers.d.ts.map +0 -1
- package/dist/core/metrics-helpers.js +0 -72
- package/dist/core/metrics-helpers.js.map +0 -1
- package/dist/core/otel-provider.d.ts +0 -54
- package/dist/core/otel-provider.d.ts.map +0 -1
- package/dist/core/otel-provider.js +0 -107
- package/dist/core/otel-provider.js.map +0 -1
- package/dist/core/procedure-graph.d.ts +0 -136
- package/dist/core/procedure-graph.d.ts.map +0 -1
- package/dist/core/procedure-graph.js +0 -272
- package/dist/core/procedure-graph.js.map +0 -1
- package/dist/core/procedure.d.ts +0 -755
- package/dist/core/procedure.d.ts.map +0 -1
- package/dist/core/procedure.js +0 -899
- package/dist/core/procedure.js.map +0 -1
- package/dist/core/stream.d.ts +0 -106
- package/dist/core/stream.d.ts.map +0 -1
- package/dist/core/stream.js +0 -186
- package/dist/core/stream.js.map +0 -1
- package/dist/core/telemetry.d.ts +0 -182
- package/dist/core/telemetry.d.ts.map +0 -1
- package/dist/core/telemetry.js +0 -124
- package/dist/core/telemetry.js.map +0 -1
- package/dist/engine/execution-graph.d.ts +0 -104
- package/dist/engine/execution-graph.d.ts.map +0 -1
- package/dist/engine/execution-graph.js +0 -257
- package/dist/engine/execution-graph.js.map +0 -1
- package/dist/hooks/policy-context.d.ts.map +0 -1
- package/dist/jsx/components/agent.d.ts +0 -64
- package/dist/jsx/components/agent.d.ts.map +0 -1
- package/dist/jsx/components/agent.js +0 -80
- package/dist/jsx/components/agent.js.map +0 -1
- package/dist/model/simple-adapter.d.ts +0 -176
- package/dist/model/simple-adapter.d.ts.map +0 -1
- package/dist/model/simple-adapter.js +0 -264
- package/dist/model/simple-adapter.js.map +0 -1
- package/dist/state/boundary.d.ts +0 -347
- package/dist/state/boundary.d.ts.map +0 -1
- package/dist/state/boundary.js +0 -341
- package/dist/state/boundary.js.map +0 -1
- package/dist/state/context.d.ts +0 -138
- package/dist/state/context.d.ts.map +0 -1
- package/dist/state/context.js +0 -139
- package/dist/state/context.js.map +0 -1
- package/dist/state/hooks.d.ts +0 -798
- package/dist/state/hooks.d.ts.map +0 -1
- package/dist/state/hooks.js +0 -1437
- package/dist/state/hooks.js.map +0 -1
- package/dist/state/index.d.ts +0 -72
- package/dist/state/index.d.ts.map +0 -1
- package/dist/state/index.js +0 -73
- package/dist/state/index.js.map +0 -1
- package/dist/state/signal.d.ts +0 -223
- package/dist/state/signal.d.ts.map +0 -1
- package/dist/state/signal.js +0 -699
- package/dist/state/signal.js.map +0 -1
- package/dist/state/use-state.d.ts +0 -210
- package/dist/state/use-state.d.ts.map +0 -1
- package/dist/state/use-state.js +0 -327
- package/dist/state/use-state.js.map +0 -1
- package/dist/tentickle-instance.d.ts +0 -285
- package/dist/tentickle-instance.d.ts.map +0 -1
- package/dist/tentickle-instance.js +0 -700
- package/dist/tentickle-instance.js.map +0 -1
- package/dist/testing/test-model.d.ts +0 -132
- package/dist/testing/test-model.d.ts.map +0 -1
- package/dist/testing/test-model.js +0 -260
- package/dist/testing/test-model.js.map +0 -1
- package/dist/v2/reconciler/host-config.d.ts +0 -31
- package/dist/v2/reconciler/host-config.d.ts.map +0 -1
- package/dist/v2/reconciler/host-config.js +0 -197
- package/dist/v2/reconciler/host-config.js.map +0 -1
- package/dist/v2/reconciler/index.d.ts +0 -7
- package/dist/v2/reconciler/index.d.ts.map +0 -1
- package/dist/v2/reconciler/index.js +0 -7
- package/dist/v2/reconciler/index.js.map +0 -1
- package/dist/v2/reconciler/reconciler.d.ts +0 -39
- package/dist/v2/reconciler/reconciler.d.ts.map +0 -1
- package/dist/v2/reconciler/reconciler.js +0 -54
- package/dist/v2/reconciler/reconciler.js.map +0 -1
- package/dist/v2/reconciler/types.d.ts +0 -64
- package/dist/v2/reconciler/types.d.ts.map +0 -1
- package/dist/v2/reconciler/types.js +0 -20
- package/dist/v2/reconciler/types.js.map +0 -1
- package/dist/v2/renderers/index.d.ts +0 -7
- package/dist/v2/renderers/index.d.ts.map +0 -1
- package/dist/v2/renderers/index.js +0 -7
- package/dist/v2/renderers/index.js.map +0 -1
- package/dist/v2/renderers/markdown.d.ts +0 -16
- package/dist/v2/renderers/markdown.d.ts.map +0 -1
- package/dist/v2/renderers/markdown.js +0 -65
- package/dist/v2/renderers/markdown.js.map +0 -1
- package/dist/v2/renderers/types.d.ts +0 -26
- package/dist/v2/renderers/types.d.ts.map +0 -1
- package/dist/v2/renderers/types.js +0 -6
- package/dist/v2/renderers/types.js.map +0 -1
- package/dist/v2/renderers/xml.d.ts +0 -17
- package/dist/v2/renderers/xml.d.ts.map +0 -1
- package/dist/v2/renderers/xml.js +0 -73
- package/dist/v2/renderers/xml.js.map +0 -1
package/dist/core/context.d.ts
DELETED
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "node:events";
|
|
2
|
-
import { type ChannelServiceInterface } from "./channel";
|
|
3
|
-
import { ProcedureGraph } from "./procedure-graph";
|
|
4
|
-
import type { ProcedureNode } from "./procedure-graph";
|
|
5
|
-
import type { Middleware } from "./procedure";
|
|
6
|
-
/**
|
|
7
|
-
* User information associated with the current execution context.
|
|
8
|
-
*
|
|
9
|
-
* This is typically populated from authentication/authorization systems
|
|
10
|
-
* and flows through all operations via the `KernelContext`.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const ctx = Context.create({
|
|
15
|
-
* user: {
|
|
16
|
-
* id: 'user-123',
|
|
17
|
-
* tenantId: 'tenant-abc',
|
|
18
|
-
* roles: ['admin', 'editor'],
|
|
19
|
-
* email: 'user@example.com', // Custom fields allowed
|
|
20
|
-
* }
|
|
21
|
-
* });
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @see {@link KernelContext.user} - Where user context is stored
|
|
25
|
-
*/
|
|
26
|
-
export interface UserContext {
|
|
27
|
-
/** Unique identifier for the user */
|
|
28
|
-
id: string;
|
|
29
|
-
/** Multi-tenant organization identifier */
|
|
30
|
-
tenantId?: string;
|
|
31
|
-
/** User's roles for authorization */
|
|
32
|
-
roles?: string[];
|
|
33
|
-
/** Additional user properties (extensible) */
|
|
34
|
-
[key: string]: any;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Event emitted during procedure execution.
|
|
38
|
-
*
|
|
39
|
-
* Events are emitted to both the global request bus (`ctx.events`)
|
|
40
|
-
* and the operation handle (`ctx.executionHandle`) if present.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* ctx.events.on('stream:chunk', (event: ExecutionEvent) => {
|
|
45
|
-
* console.log(`[${event.source}] ${event.type}:`, event.payload);
|
|
46
|
-
* });
|
|
47
|
-
*
|
|
48
|
-
* // Listen to all events
|
|
49
|
-
* ctx.events.on('*', (event: ExecutionEvent) => {
|
|
50
|
-
* console.log(`Event: ${event.type}`);
|
|
51
|
-
* });
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* @see {@link Context.emit} - Emit events to the current context
|
|
55
|
-
*/
|
|
56
|
-
export interface ExecutionEvent {
|
|
57
|
-
/** Event type (e.g., 'stream:chunk', 'procedure:error') */
|
|
58
|
-
type: string;
|
|
59
|
-
/** Event payload data */
|
|
60
|
-
payload: any;
|
|
61
|
-
/** Unix timestamp when the event occurred */
|
|
62
|
-
timestamp: number;
|
|
63
|
-
/** Source of the event (e.g., 'agent:sales', 'model:openai') */
|
|
64
|
-
source: string;
|
|
65
|
-
/** Trace ID for correlation (distributed tracing) */
|
|
66
|
-
traceId: string;
|
|
67
|
-
/** Request ID for this execution context */
|
|
68
|
-
requestId?: string;
|
|
69
|
-
/** Execution ID from context (auto-populated if available) */
|
|
70
|
-
executionId?: string;
|
|
71
|
-
/** Parent execution ID for nested executions (fork, spawn, component_tool) */
|
|
72
|
-
parentExecutionId?: string;
|
|
73
|
-
/** Procedure ID from context (auto-populated if available) */
|
|
74
|
-
procedureId?: string;
|
|
75
|
-
/** Current tick number if in a tick context */
|
|
76
|
-
tick?: number;
|
|
77
|
-
/** User ID from context (for attribution and multi-tenant filtering) */
|
|
78
|
-
userId?: string;
|
|
79
|
-
/** Tenant ID from context (for multi-tenant dashboards) */
|
|
80
|
-
tenantId?: string;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Extensible metadata storage within the context.
|
|
84
|
-
*
|
|
85
|
-
* Use this to store application-specific data that should flow
|
|
86
|
-
* through the execution context.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* const ctx = Context.create({
|
|
91
|
-
* metadata: {
|
|
92
|
-
* conversationId: 'conv-123',
|
|
93
|
-
* feature_flags: { beta: true },
|
|
94
|
-
* }
|
|
95
|
-
* });
|
|
96
|
-
*
|
|
97
|
-
* // Access later
|
|
98
|
-
* const convId = Context.get().metadata.conversationId;
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
export interface ContextMetadata extends Record<string, any> {
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Metrics accumulated during procedure execution.
|
|
105
|
-
*
|
|
106
|
-
* Metrics are automatically propagated from child procedures to parents
|
|
107
|
-
* when execution completes.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```typescript
|
|
111
|
-
* // In a procedure
|
|
112
|
-
* addMetric(ctx, 'tokens.input', 100);
|
|
113
|
-
* addMetric(ctx, 'api_calls', 1);
|
|
114
|
-
*
|
|
115
|
-
* // After execution, parent has accumulated metrics
|
|
116
|
-
* const totalTokens = ctx.metrics['tokens.input'];
|
|
117
|
-
* ```
|
|
118
|
-
*
|
|
119
|
-
* @see {@link addMetric} - Accumulate a metric value
|
|
120
|
-
* @see {@link getUsageMetrics} - Get token usage metrics
|
|
121
|
-
*/
|
|
122
|
-
export interface ContextMetrics extends Record<string, any> {
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Execution context that flows through all async operations via AsyncLocalStorage.
|
|
126
|
-
*
|
|
127
|
-
* The `KernelContext` contains all state needed during execution:
|
|
128
|
-
* - Identity and tracing (requestId, traceId, user)
|
|
129
|
-
* - Event buses (events, executionHandle)
|
|
130
|
-
* - Cancellation (signal)
|
|
131
|
-
* - Communication (channels)
|
|
132
|
-
* - Execution tracking (procedureGraph, procedurePid, origin)
|
|
133
|
-
* - Extensible storage (metadata, metrics)
|
|
134
|
-
*
|
|
135
|
-
* Access the current context with `Context.get()` from anywhere in your code -
|
|
136
|
-
* no need to pass it explicitly through function calls.
|
|
137
|
-
*
|
|
138
|
-
* @example Creating and running with context
|
|
139
|
-
* ```typescript
|
|
140
|
-
* const ctx = Context.create({
|
|
141
|
-
* user: { id: 'user-1' },
|
|
142
|
-
* metadata: { conversationId: 'conv-123' }
|
|
143
|
-
* });
|
|
144
|
-
*
|
|
145
|
-
* await Context.run(ctx, async () => {
|
|
146
|
-
* // Context is available here and in all async calls
|
|
147
|
-
* const current = Context.get();
|
|
148
|
-
* console.log(current.user?.id); // 'user-1'
|
|
149
|
-
* });
|
|
150
|
-
* ```
|
|
151
|
-
*
|
|
152
|
-
* @example Extending for your application
|
|
153
|
-
* ```typescript
|
|
154
|
-
* interface AppContext extends KernelContext {
|
|
155
|
-
* customHandle?: MyCustomHandle;
|
|
156
|
-
* appMetadata: AppSpecificMetadata;
|
|
157
|
-
* }
|
|
158
|
-
* ```
|
|
159
|
-
*
|
|
160
|
-
* @see {@link Context} - Static methods to create/access context
|
|
161
|
-
* @see {@link UserContext} - User information structure
|
|
162
|
-
*/
|
|
163
|
-
export interface KernelContext {
|
|
164
|
-
/** Unique identifier for this request/execution */
|
|
165
|
-
requestId: string;
|
|
166
|
-
/** Correlation ID for distributed tracing */
|
|
167
|
-
traceId: string;
|
|
168
|
-
/** User information (from auth) */
|
|
169
|
-
user?: UserContext;
|
|
170
|
-
/** Application-specific metadata */
|
|
171
|
-
metadata: ContextMetadata;
|
|
172
|
-
/** Accumulated execution metrics */
|
|
173
|
-
metrics: ContextMetrics;
|
|
174
|
-
/** Global request event bus for subscribing to all events */
|
|
175
|
-
events: EventEmitter;
|
|
176
|
-
/** Abort signal for cooperative cancellation */
|
|
177
|
-
signal?: AbortSignal;
|
|
178
|
-
/** Operation-specific event emitter (from `.withHandle()`) */
|
|
179
|
-
executionHandle?: EventEmitter;
|
|
180
|
-
/**
|
|
181
|
-
* Channel service for bidirectional communication (optional).
|
|
182
|
-
* Injected by Engine when channels are configured.
|
|
183
|
-
* Tools and components can access channels via this service.
|
|
184
|
-
*/
|
|
185
|
-
channels?: ChannelServiceInterface;
|
|
186
|
-
/**
|
|
187
|
-
* Procedure graph for tracking procedure execution hierarchy.
|
|
188
|
-
* Automatically initialized when first procedure is executed.
|
|
189
|
-
*/
|
|
190
|
-
procedureGraph?: ProcedureGraph;
|
|
191
|
-
/**
|
|
192
|
-
* Current procedure PID (for tracking nested procedures).
|
|
193
|
-
*/
|
|
194
|
-
procedurePid?: string;
|
|
195
|
-
/** Current procedure node in the graph */
|
|
196
|
-
procedureNode?: ProcedureNode;
|
|
197
|
-
/**
|
|
198
|
-
* Origin procedure node - the root procedure that initiated this execution chain.
|
|
199
|
-
* Undefined for the root procedure itself (since it IS the origin).
|
|
200
|
-
* Set automatically by ExecutionTracker when procedures are executed.
|
|
201
|
-
*/
|
|
202
|
-
origin?: ProcedureNode;
|
|
203
|
-
/**
|
|
204
|
-
* Current execution ID. Set when entering an execution boundary.
|
|
205
|
-
* All procedures within this execution share this ID.
|
|
206
|
-
*/
|
|
207
|
-
executionId?: string;
|
|
208
|
-
/**
|
|
209
|
-
* Type of execution at this boundary (e.g., 'engine', 'model', 'component_tool', 'fork', 'spawn').
|
|
210
|
-
* Only meaningful at execution boundaries.
|
|
211
|
-
*/
|
|
212
|
-
executionType?: string;
|
|
213
|
-
/**
|
|
214
|
-
* Parent execution ID for nested executions (e.g., component_tool called from engine).
|
|
215
|
-
* Enables DevTools to show execution hierarchy.
|
|
216
|
-
*/
|
|
217
|
-
parentExecutionId?: string;
|
|
218
|
-
/**
|
|
219
|
-
* Current tick number (set by engine during tick loop).
|
|
220
|
-
* Enables events to include tick context for correlation.
|
|
221
|
-
*/
|
|
222
|
-
tick?: number;
|
|
223
|
-
/**
|
|
224
|
-
* Middleware registry for procedure execution.
|
|
225
|
-
* Procedures read this at execution time to get instance-level middleware.
|
|
226
|
-
* Typically set by createApp() from the Tentickle instance.
|
|
227
|
-
*/
|
|
228
|
-
middleware?: {
|
|
229
|
-
getMiddlewareFor(procedureName: string): Middleware[];
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* Type brand for context detection
|
|
233
|
-
*/
|
|
234
|
-
[KERNEL_CONTEXT_SYMBOL]?: boolean;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Static class for managing execution context via AsyncLocalStorage.
|
|
238
|
-
*
|
|
239
|
-
* Context flows automatically through all async operations without explicit passing.
|
|
240
|
-
* Use `Context.run()` to establish context, and `Context.get()` to access it.
|
|
241
|
-
*
|
|
242
|
-
* @example Basic usage
|
|
243
|
-
* ```typescript
|
|
244
|
-
* // Create and run with context
|
|
245
|
-
* const ctx = Context.create({ user: { id: 'user-1' } });
|
|
246
|
-
* await Context.run(ctx, async () => {
|
|
247
|
-
* const current = Context.get();
|
|
248
|
-
* console.log(current.user?.id); // 'user-1'
|
|
249
|
-
*
|
|
250
|
-
* // Context flows to nested calls
|
|
251
|
-
* await someAsyncFunction(); // Can access Context.get() inside
|
|
252
|
-
* });
|
|
253
|
-
* ```
|
|
254
|
-
*
|
|
255
|
-
* @example Parallel execution with child contexts
|
|
256
|
-
* ```typescript
|
|
257
|
-
* // Each parallel task gets its own context to avoid races
|
|
258
|
-
* const [a, b] = await Promise.all([
|
|
259
|
-
* Context.fork({ procedurePid: 'task-1' }, () => doTask1()),
|
|
260
|
-
* Context.fork({ procedurePid: 'task-2' }, () => doTask2()),
|
|
261
|
-
* ]);
|
|
262
|
-
* ```
|
|
263
|
-
*
|
|
264
|
-
* @example Emitting events
|
|
265
|
-
* ```typescript
|
|
266
|
-
* // Events go to both global bus and operation handle
|
|
267
|
-
* Context.emit('progress', { percent: 50 }, 'my-tool');
|
|
268
|
-
* ```
|
|
269
|
-
*
|
|
270
|
-
* @see {@link KernelContext} - The context interface
|
|
271
|
-
* @see {@link context} - Brand an object as context for procedure detection
|
|
272
|
-
*/
|
|
273
|
-
export declare class Context {
|
|
274
|
-
/**
|
|
275
|
-
* Creates a new root context with default values.
|
|
276
|
-
*
|
|
277
|
-
* @param overrides - Partial context to merge with defaults
|
|
278
|
-
* @returns A new KernelContext
|
|
279
|
-
*
|
|
280
|
-
* @example
|
|
281
|
-
* ```typescript
|
|
282
|
-
* const ctx = Context.create({
|
|
283
|
-
* user: { id: 'user-1' },
|
|
284
|
-
* metadata: { feature: 'chat' }
|
|
285
|
-
* });
|
|
286
|
-
* ```
|
|
287
|
-
*/
|
|
288
|
-
static create(overrides?: Partial<Omit<KernelContext, "events">>): KernelContext;
|
|
289
|
-
static brand(ctx: Partial<KernelContext>): KernelContext;
|
|
290
|
-
/**
|
|
291
|
-
* Runs a function within the given context.
|
|
292
|
-
* All async operations within `fn` will have access to this context.
|
|
293
|
-
*
|
|
294
|
-
* @param context - The context to run within
|
|
295
|
-
* @param fn - Async function to execute
|
|
296
|
-
* @returns The result of the function
|
|
297
|
-
*/
|
|
298
|
-
static run<T>(ctx: Partial<KernelContext>, fn: () => Promise<T>): Promise<T>;
|
|
299
|
-
/**
|
|
300
|
-
* Creates a child context that inherits from the current context (or creates a new root).
|
|
301
|
-
* The child context is a shallow copy - objects like `events`, `procedureGraph`, and `channels`
|
|
302
|
-
* are shared with the parent (intentionally, for coordination).
|
|
303
|
-
*
|
|
304
|
-
* Scalar values like `procedurePid`, `procedureNode`, and `origin` can be safely
|
|
305
|
-
* overridden in the child without affecting the parent.
|
|
306
|
-
*
|
|
307
|
-
* @param overrides - Properties to override in the child context
|
|
308
|
-
* @returns A new context object inheriting from the current context
|
|
309
|
-
*
|
|
310
|
-
* @example
|
|
311
|
-
* ```typescript
|
|
312
|
-
* // Create child context with new procedure ID
|
|
313
|
-
* const childCtx = Context.child({ procedurePid: 'new-pid' });
|
|
314
|
-
* await Context.run(childCtx, async () => {
|
|
315
|
-
* // This context has its own procedurePid but shares events, graph, etc.
|
|
316
|
-
* });
|
|
317
|
-
* ```
|
|
318
|
-
*/
|
|
319
|
-
static child(overrides?: Partial<KernelContext>): KernelContext;
|
|
320
|
-
/**
|
|
321
|
-
* Creates a child context and runs a function within it.
|
|
322
|
-
* Convenience method combining `child()` and `run()`.
|
|
323
|
-
*
|
|
324
|
-
* This is the safe way to run parallel procedures - each gets its own
|
|
325
|
-
* context object so mutations don't race.
|
|
326
|
-
*
|
|
327
|
-
* @param overrides - Properties to override in the child context
|
|
328
|
-
* @param fn - Function to run within the child context
|
|
329
|
-
* @returns The result of the function
|
|
330
|
-
*
|
|
331
|
-
* @example
|
|
332
|
-
* ```typescript
|
|
333
|
-
* // Run parallel procedures safely
|
|
334
|
-
* const [result1, result2] = await Promise.all([
|
|
335
|
-
* Context.fork({ procedurePid: 'proc-1' }, async () => doWork1()),
|
|
336
|
-
* Context.fork({ procedurePid: 'proc-2' }, async () => doWork2()),
|
|
337
|
-
* ]);
|
|
338
|
-
* ```
|
|
339
|
-
*/
|
|
340
|
-
static fork<T>(overrides: Partial<KernelContext>, fn: () => Promise<T>): Promise<T>;
|
|
341
|
-
/**
|
|
342
|
-
* Gets the current context. Throws if not found.
|
|
343
|
-
*/
|
|
344
|
-
static get(): KernelContext;
|
|
345
|
-
/**
|
|
346
|
-
* Gets the current context or returns undefined if not found.
|
|
347
|
-
*/
|
|
348
|
-
static tryGet(): KernelContext | undefined;
|
|
349
|
-
/**
|
|
350
|
-
* Set the current tick number in the context.
|
|
351
|
-
* Called by the engine at the start of each tick.
|
|
352
|
-
*/
|
|
353
|
-
static setTick(tick: number): void;
|
|
354
|
-
/**
|
|
355
|
-
* Helper to emit an event on the current context.
|
|
356
|
-
* Events are broadcast to:
|
|
357
|
-
* 1. The context's local event bus (ctx.events)
|
|
358
|
-
* 2. The operation handle (ctx.executionHandle) if present
|
|
359
|
-
* 3. All global subscribers registered via subscribeGlobal()
|
|
360
|
-
*/
|
|
361
|
-
static emit(type: string, payload: any, source?: string): void;
|
|
362
|
-
/**
|
|
363
|
-
* Subscribe to ALL context events globally.
|
|
364
|
-
* This is useful for observability tools like DevTools that need to see
|
|
365
|
-
* all procedure:start/end/error events across all contexts.
|
|
366
|
-
*
|
|
367
|
-
* @param handler - Callback that receives every event with its context
|
|
368
|
-
* @returns Unsubscribe function
|
|
369
|
-
*
|
|
370
|
-
* @example
|
|
371
|
-
* ```typescript
|
|
372
|
-
* const unsubscribe = Context.subscribeGlobal((event, ctx) => {
|
|
373
|
-
* if (event.type === 'procedure:start') {
|
|
374
|
-
* console.log(`Procedure ${event.payload.name} started`);
|
|
375
|
-
* }
|
|
376
|
-
* });
|
|
377
|
-
*
|
|
378
|
-
* // Later, to stop receiving events:
|
|
379
|
-
* unsubscribe();
|
|
380
|
-
* ```
|
|
381
|
-
*/
|
|
382
|
-
static subscribeGlobal(handler: (event: ExecutionEvent, ctx: KernelContext) => void): () => void;
|
|
383
|
-
/**
|
|
384
|
-
* Check if there are any global subscribers.
|
|
385
|
-
* Useful for conditional event emission to avoid overhead when no one is listening.
|
|
386
|
-
*/
|
|
387
|
-
static hasGlobalSubscribers(): boolean;
|
|
388
|
-
}
|
|
389
|
-
export declare class ContextProvider {
|
|
390
|
-
withContext<T>(context: KernelContext, fn: () => Promise<T>): Promise<T>;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Symbol used to brand context objects for deterministic detection.
|
|
394
|
-
* This allows procedures to distinguish context from regular arguments.
|
|
395
|
-
*/
|
|
396
|
-
export declare const KERNEL_CONTEXT_SYMBOL: unique symbol;
|
|
397
|
-
/**
|
|
398
|
-
* Brand a context object with a Symbol for deterministic detection.
|
|
399
|
-
* This allows procedures to deterministically identify context vs regular args.
|
|
400
|
-
*
|
|
401
|
-
* @example
|
|
402
|
-
* ```typescript
|
|
403
|
-
* await proc(input, agent, context({ traceId: "123" }));
|
|
404
|
-
* ```
|
|
405
|
-
*/
|
|
406
|
-
export declare function context(ctx: Partial<KernelContext>): Partial<KernelContext>;
|
|
407
|
-
/**
|
|
408
|
-
* Check if an object is a branded context (deterministic check via Symbol).
|
|
409
|
-
* This is 100% reliable - no heuristics needed.
|
|
410
|
-
*/
|
|
411
|
-
export declare function isKernelContext(obj: any): obj is Partial<KernelContext>;
|
|
412
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,WAAW;IAC1B,qCAAqC;IACrC,EA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