@ekairos/events 1.22.35-beta.development.0 → 1.22.35
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 +5 -3
- package/dist/codex.d.ts +11 -2
- package/dist/codex.js +16 -8
- package/dist/context.action-calls.d.ts +48 -0
- package/dist/context.action-calls.js +123 -0
- package/dist/context.action.d.ts +55 -0
- package/dist/context.action.js +25 -0
- package/dist/context.builder.d.ts +71 -43
- package/dist/context.builder.js +123 -28
- package/dist/context.config.d.ts +2 -1
- package/dist/context.config.js +8 -3
- package/dist/context.contract.d.ts +2 -4
- package/dist/context.contract.js +3 -9
- package/dist/context.d.ts +3 -2
- package/dist/context.engine.d.ts +60 -52
- package/dist/context.engine.js +506 -297
- package/dist/context.events.js +28 -87
- package/dist/context.js +1 -0
- package/dist/context.part-identity.d.ts +40 -0
- package/dist/context.part-identity.js +270 -0
- package/dist/context.parts.d.ts +389 -164
- package/dist/context.parts.js +343 -218
- package/dist/context.registry.d.ts +1 -1
- package/dist/context.runtime.d.ts +14 -4
- package/dist/context.runtime.js +21 -3
- package/dist/context.step-stream.d.ts +16 -2
- package/dist/context.step-stream.js +58 -16
- package/dist/context.store.d.ts +55 -10
- package/dist/context.stream.d.ts +14 -4
- package/dist/context.stream.js +31 -3
- package/dist/domain.d.ts +1 -0
- package/dist/domain.js +1 -0
- package/dist/index.d.ts +13 -10
- package/dist/index.js +7 -6
- package/dist/react.context-event-parts.d.ts +18 -0
- package/dist/react.context-event-parts.js +509 -0
- package/dist/react.d.ts +7 -42
- package/dist/react.js +4 -87
- package/dist/react.step-stream.d.ts +39 -0
- package/dist/react.step-stream.js +625 -0
- package/dist/react.types.d.ts +121 -0
- package/dist/react.types.js +2 -0
- package/dist/react.use-context.d.ts +7 -0
- package/dist/react.use-context.js +867 -0
- package/dist/reactors/ai-sdk.chunk-map.d.ts +1 -0
- package/dist/reactors/ai-sdk.chunk-map.js +56 -5
- package/dist/reactors/ai-sdk.reactor.d.ts +8 -9
- package/dist/reactors/ai-sdk.reactor.js +6 -9
- package/dist/reactors/ai-sdk.step.d.ts +4 -5
- package/dist/reactors/ai-sdk.step.js +24 -17
- package/dist/reactors/scripted.reactor.d.ts +7 -4
- package/dist/reactors/types.d.ts +19 -10
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +9 -0
- package/dist/runtime.step.js +1 -1
- package/dist/schema.d.ts +268 -2
- package/dist/schema.js +4 -9
- package/dist/steps/do-context-stream-step.js +4 -4
- package/dist/steps/durable.steps.d.ts +28 -0
- package/dist/steps/durable.steps.js +34 -0
- package/dist/steps/store.steps.d.ts +64 -22
- package/dist/steps/store.steps.js +192 -35
- package/dist/steps/stream.steps.d.ts +32 -0
- package/dist/steps/stream.steps.js +124 -6
- package/dist/steps/trace.steps.d.ts +4 -4
- package/dist/steps/trace.steps.js +21 -6
- package/dist/stores/instant.store.d.ts +11 -11
- package/dist/stores/instant.store.js +136 -6
- package/dist/tools-to-model-tools.d.ts +4 -2
- package/dist/tools-to-model-tools.js +30 -11
- package/package.json +18 -7
- package/dist/context.toolcalls.d.ts +0 -60
- package/dist/context.toolcalls.js +0 -117
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import type { ConcreteDomain } from "@ekairos/domain";
|
|
2
|
-
import type {
|
|
1
|
+
import type { ConcreteDomain, DomainLike } from "@ekairos/domain";
|
|
2
|
+
import type { EkairosRuntime, RuntimeForDomain, RuntimeResolveOptions } from "@ekairos/domain/runtime";
|
|
3
3
|
import type { ContextEnvironment } from "./context.config.js";
|
|
4
4
|
import type { ContextStore } from "./context.store.js";
|
|
5
|
-
|
|
5
|
+
import { eventsDomain } from "./schema.js";
|
|
6
|
+
export type ContextRuntime<Env extends ContextEnvironment = ContextEnvironment> = EkairosRuntime<Env, any, any>;
|
|
7
|
+
export type ContextRuntimeServiceHandle = {
|
|
8
|
+
db: any | ((...args: any[]) => Promise<any> | any);
|
|
9
|
+
resolve?: (...args: any[]) => Promise<any> | any;
|
|
10
|
+
meta?: (...args: any[]) => Record<string, unknown> | undefined;
|
|
11
|
+
};
|
|
12
|
+
export type ContextRuntimeHandleForDomain<Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain> = ContextRuntimeServiceHandle & {
|
|
13
|
+
use<Subdomain extends typeof eventsDomain | RequiredDomain>(subdomain: Subdomain, options?: RuntimeResolveOptions): Promise<unknown>;
|
|
14
|
+
};
|
|
15
|
+
export type ContextRuntimeForDomain<Runtime extends ContextRuntime<any>, RequiredDomain extends DomainLike = typeof eventsDomain> = RuntimeForDomain<Runtime, typeof eventsDomain> & RuntimeForDomain<Runtime, RequiredDomain>;
|
|
6
16
|
export type ContextRuntimeServices = {
|
|
7
17
|
db: any;
|
|
8
18
|
store: ContextStore;
|
|
9
19
|
domain?: ConcreteDomain<any, any>;
|
|
10
20
|
};
|
|
11
|
-
export declare function getContextRuntimeServices(runtime:
|
|
21
|
+
export declare function getContextRuntimeServices(runtime: ContextRuntimeServiceHandle): Promise<ContextRuntimeServices>;
|
package/dist/context.runtime.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
const storeByDb = new WeakMap();
|
|
2
|
+
function asRecord(value) {
|
|
3
|
+
return value && typeof value === "object" ? value : {};
|
|
4
|
+
}
|
|
2
5
|
export async function getContextRuntimeServices(runtime) {
|
|
3
|
-
const
|
|
6
|
+
const runtimeRecord = asRecord(runtime);
|
|
7
|
+
const dbMember = runtimeRecord.db;
|
|
8
|
+
const db = typeof dbMember === "function"
|
|
9
|
+
? await dbMember.call(runtime)
|
|
10
|
+
: dbMember;
|
|
4
11
|
if (!db) {
|
|
5
12
|
throw new Error("Context runtime did not provide a database instance.");
|
|
6
13
|
}
|
|
@@ -12,10 +19,21 @@ export async function getContextRuntimeServices(runtime) {
|
|
|
12
19
|
storeByDb.set(db, store);
|
|
13
20
|
}
|
|
14
21
|
}
|
|
15
|
-
const
|
|
22
|
+
const resolveMember = runtimeRecord.resolve;
|
|
23
|
+
const resolved = typeof resolveMember === "function"
|
|
24
|
+
? await resolveMember.call(runtime)
|
|
25
|
+
: runtime;
|
|
26
|
+
const resolvedMeta = asRecord(resolved).meta;
|
|
27
|
+
const ownMeta = runtimeRecord.meta;
|
|
28
|
+
const meta = typeof resolvedMeta === "function"
|
|
29
|
+
? resolvedMeta.call(resolved)
|
|
30
|
+
: typeof ownMeta === "function"
|
|
31
|
+
? ownMeta.call(runtime)
|
|
32
|
+
: undefined;
|
|
33
|
+
const domain = asRecord(meta).domain;
|
|
16
34
|
return {
|
|
17
35
|
db,
|
|
18
36
|
store,
|
|
19
|
-
domain:
|
|
37
|
+
domain: domain,
|
|
20
38
|
};
|
|
21
39
|
}
|
|
@@ -5,22 +5,36 @@ export type ContextStepStreamChunk = {
|
|
|
5
5
|
at: string;
|
|
6
6
|
sequence: number;
|
|
7
7
|
chunkType: ContextStreamChunkType;
|
|
8
|
+
partId?: string;
|
|
9
|
+
providerPartId?: string;
|
|
10
|
+
partType?: string;
|
|
11
|
+
partSlot?: string;
|
|
8
12
|
provider?: string;
|
|
9
13
|
providerChunkType?: string;
|
|
10
14
|
actionRef?: string;
|
|
11
15
|
data?: unknown;
|
|
12
16
|
raw?: unknown;
|
|
13
17
|
};
|
|
18
|
+
export type ContextStepStreamChunkValidationOptions = {
|
|
19
|
+
stepId?: string;
|
|
20
|
+
label?: string;
|
|
21
|
+
};
|
|
14
22
|
export declare function createContextStepStreamChunk(params: {
|
|
15
23
|
at?: string;
|
|
16
24
|
sequence: number;
|
|
17
25
|
chunkType: ContextStreamChunkType;
|
|
26
|
+
stepId?: string;
|
|
27
|
+
partId?: string;
|
|
28
|
+
providerPartId?: string;
|
|
29
|
+
partType?: string;
|
|
30
|
+
partSlot?: string;
|
|
18
31
|
provider?: string;
|
|
19
32
|
providerChunkType?: string;
|
|
20
33
|
actionRef?: string;
|
|
21
34
|
data?: unknown;
|
|
22
35
|
raw?: unknown;
|
|
23
36
|
}): ContextStepStreamChunk;
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function
|
|
37
|
+
export declare function validateContextStepStreamChunk(value: unknown, options?: ContextStepStreamChunkValidationOptions): asserts value is ContextStepStreamChunk;
|
|
38
|
+
export declare function parseContextStepStreamChunk(value: string | unknown, options?: ContextStepStreamChunkValidationOptions): ContextStepStreamChunk;
|
|
39
|
+
export declare function encodeContextStepStreamChunk(chunk: ContextStepStreamChunk, options?: ContextStepStreamChunkValidationOptions): string;
|
|
26
40
|
export declare function contextStreamByteLength(value: string): number;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isContextStreamChunkType, } from "./context.contract.js";
|
|
2
|
+
import { assertValidContextPartChunkIdentity } from "./context.part-identity.js";
|
|
2
3
|
export const CONTEXT_STEP_STREAM_VERSION = 1;
|
|
3
4
|
function assertObject(value, label) {
|
|
4
5
|
if (!value || typeof value !== "object") {
|
|
@@ -15,43 +16,84 @@ function assertNumber(value, label) {
|
|
|
15
16
|
throw new Error(`Invalid ${label}: expected number.`);
|
|
16
17
|
}
|
|
17
18
|
}
|
|
19
|
+
function assertPositiveInteger(value, label) {
|
|
20
|
+
assertNumber(value, label);
|
|
21
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
22
|
+
throw new Error(`Invalid ${label}: expected positive integer.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function assertIsoDateString(value, label) {
|
|
26
|
+
assertString(value, label);
|
|
27
|
+
if (Number.isNaN(Date.parse(value))) {
|
|
28
|
+
throw new Error(`Invalid ${label}: expected ISO date string.`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
18
31
|
function assertOptionalString(value, label) {
|
|
19
32
|
if (typeof value === "undefined")
|
|
20
33
|
return;
|
|
21
34
|
assertString(value, label);
|
|
22
35
|
}
|
|
23
36
|
export function createContextStepStreamChunk(params) {
|
|
24
|
-
|
|
37
|
+
const chunk = {
|
|
25
38
|
version: CONTEXT_STEP_STREAM_VERSION,
|
|
26
39
|
at: params.at ?? new Date().toISOString(),
|
|
27
40
|
sequence: params.sequence,
|
|
28
41
|
chunkType: params.chunkType,
|
|
42
|
+
partId: params.partId,
|
|
43
|
+
providerPartId: params.providerPartId,
|
|
44
|
+
partType: params.partType,
|
|
45
|
+
partSlot: params.partSlot,
|
|
29
46
|
provider: params.provider,
|
|
30
47
|
providerChunkType: params.providerChunkType,
|
|
31
48
|
actionRef: params.actionRef,
|
|
32
49
|
data: params.data,
|
|
33
50
|
raw: params.raw,
|
|
34
51
|
};
|
|
52
|
+
validateContextStepStreamChunk(chunk, {
|
|
53
|
+
stepId: params.stepId,
|
|
54
|
+
label: "context step stream chunk",
|
|
55
|
+
});
|
|
56
|
+
return chunk;
|
|
35
57
|
}
|
|
36
|
-
export function
|
|
37
|
-
const
|
|
38
|
-
assertObject(
|
|
39
|
-
assertNumber(
|
|
40
|
-
if (
|
|
41
|
-
throw new Error(`Unsupported
|
|
58
|
+
export function validateContextStepStreamChunk(value, options = {}) {
|
|
59
|
+
const label = options.label ?? "context step stream chunk";
|
|
60
|
+
assertObject(value, label);
|
|
61
|
+
assertNumber(value.version, `${label}.version`);
|
|
62
|
+
if (value.version !== CONTEXT_STEP_STREAM_VERSION) {
|
|
63
|
+
throw new Error(`Unsupported ${label}.version: ${String(value.version)}`);
|
|
42
64
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
assertString(
|
|
46
|
-
if (!isContextStreamChunkType(
|
|
47
|
-
throw new Error(`Invalid
|
|
65
|
+
assertIsoDateString(value.at, `${label}.at`);
|
|
66
|
+
assertPositiveInteger(value.sequence, `${label}.sequence`);
|
|
67
|
+
assertString(value.chunkType, `${label}.chunkType`);
|
|
68
|
+
if (!isContextStreamChunkType(value.chunkType)) {
|
|
69
|
+
throw new Error(`Invalid ${label}.chunkType: ${String(value.chunkType)}`);
|
|
48
70
|
}
|
|
49
|
-
assertOptionalString(
|
|
50
|
-
assertOptionalString(
|
|
51
|
-
assertOptionalString(
|
|
71
|
+
assertOptionalString(value.partId, `${label}.partId`);
|
|
72
|
+
assertOptionalString(value.providerPartId, `${label}.providerPartId`);
|
|
73
|
+
assertOptionalString(value.partType, `${label}.partType`);
|
|
74
|
+
assertOptionalString(value.partSlot, `${label}.partSlot`);
|
|
75
|
+
assertOptionalString(value.provider, `${label}.provider`);
|
|
76
|
+
assertOptionalString(value.providerChunkType, `${label}.providerChunkType`);
|
|
77
|
+
assertOptionalString(value.actionRef, `${label}.actionRef`);
|
|
78
|
+
assertValidContextPartChunkIdentity({
|
|
79
|
+
label,
|
|
80
|
+
stepId: options.stepId,
|
|
81
|
+
chunkType: value.chunkType,
|
|
82
|
+
partId: value.partId,
|
|
83
|
+
provider: value.provider,
|
|
84
|
+
providerPartId: value.providerPartId,
|
|
85
|
+
partType: value.partType,
|
|
86
|
+
partSlot: value.partSlot,
|
|
87
|
+
actionRef: value.actionRef,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
export function parseContextStepStreamChunk(value, options = {}) {
|
|
91
|
+
const parsed = typeof value === "string" ? JSON.parse(value) : value;
|
|
92
|
+
validateContextStepStreamChunk(parsed, options);
|
|
52
93
|
return parsed;
|
|
53
94
|
}
|
|
54
|
-
export function encodeContextStepStreamChunk(chunk) {
|
|
95
|
+
export function encodeContextStepStreamChunk(chunk, options = {}) {
|
|
96
|
+
validateContextStepStreamChunk(chunk, options);
|
|
55
97
|
return `${JSON.stringify(chunk)}\n`;
|
|
56
98
|
}
|
|
57
99
|
export function contextStreamByteLength(value) {
|
package/dist/context.store.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModelMessage } from "ai";
|
|
2
|
-
import type { ContextStatus, ExecutionStatus, StepStatus,
|
|
2
|
+
import type { ContextStatus, ExecutionStatus, StepStatus, ItemStatus, ItemType, Channel } from "./context.contract.js";
|
|
3
3
|
export type ContextIdentifier = {
|
|
4
4
|
id: string;
|
|
5
5
|
key?: never;
|
|
@@ -8,6 +8,50 @@ export type ContextIdentifier = {
|
|
|
8
8
|
id?: never;
|
|
9
9
|
};
|
|
10
10
|
export type { ContextStatus } from "./context.contract.js";
|
|
11
|
+
export type ContextResourceBase = {
|
|
12
|
+
key: string;
|
|
13
|
+
type: string;
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
role?: string | null;
|
|
17
|
+
metadata?: Record<string, unknown> | null;
|
|
18
|
+
};
|
|
19
|
+
export type ContextFileResource = ContextResourceBase & {
|
|
20
|
+
type: "file";
|
|
21
|
+
fileId?: string;
|
|
22
|
+
documentId?: string;
|
|
23
|
+
url?: string;
|
|
24
|
+
filename?: string;
|
|
25
|
+
mediaType?: string;
|
|
26
|
+
size?: number;
|
|
27
|
+
};
|
|
28
|
+
export type ContextLinkResource = ContextResourceBase & {
|
|
29
|
+
type: "link";
|
|
30
|
+
url: string;
|
|
31
|
+
};
|
|
32
|
+
export type ContextRepositoryResource = ContextResourceBase & {
|
|
33
|
+
type: "repository";
|
|
34
|
+
provider?: string;
|
|
35
|
+
repository: string;
|
|
36
|
+
ref?: string;
|
|
37
|
+
paths?: string[];
|
|
38
|
+
commitSha?: string;
|
|
39
|
+
};
|
|
40
|
+
export type ContextDatasetResource = ContextResourceBase & {
|
|
41
|
+
type: "dataset";
|
|
42
|
+
datasetId: string;
|
|
43
|
+
};
|
|
44
|
+
export type ContextExternalResource = ContextResourceBase & {
|
|
45
|
+
type: "external";
|
|
46
|
+
uri?: string;
|
|
47
|
+
};
|
|
48
|
+
export type ContextResource = ContextFileResource | ContextLinkResource | ContextRepositoryResource | ContextDatasetResource | ContextExternalResource | (ContextResourceBase & Record<string, unknown>);
|
|
49
|
+
export type StoredContextResource = ContextResource & {
|
|
50
|
+
id?: string;
|
|
51
|
+
storageKey?: string;
|
|
52
|
+
createdAt?: Date;
|
|
53
|
+
updatedAt?: Date;
|
|
54
|
+
};
|
|
11
55
|
export type StoredContext<Context> = {
|
|
12
56
|
id: string;
|
|
13
57
|
key: string | null;
|
|
@@ -16,6 +60,9 @@ export type StoredContext<Context> = {
|
|
|
16
60
|
createdAt: Date;
|
|
17
61
|
updatedAt?: Date;
|
|
18
62
|
content: Context | null;
|
|
63
|
+
description?: string | null;
|
|
64
|
+
goal?: string | null;
|
|
65
|
+
resources?: StoredContextResource[] | null;
|
|
19
66
|
reactor?: {
|
|
20
67
|
kind: string;
|
|
21
68
|
state?: Record<string, unknown> | null;
|
|
@@ -43,14 +90,6 @@ export type ContextStep = {
|
|
|
43
90
|
updatedAt?: Date;
|
|
44
91
|
status: StepStatus;
|
|
45
92
|
iteration: number;
|
|
46
|
-
kind?: StepKind;
|
|
47
|
-
actionName?: string;
|
|
48
|
-
actionInput?: unknown;
|
|
49
|
-
actionOutput?: unknown;
|
|
50
|
-
actionError?: string;
|
|
51
|
-
actionRequests?: any;
|
|
52
|
-
actionResults?: any;
|
|
53
|
-
continueLoop?: boolean;
|
|
54
93
|
errorText?: string;
|
|
55
94
|
};
|
|
56
95
|
export type ContextExecution = {
|
|
@@ -61,6 +100,12 @@ export interface ContextStore {
|
|
|
61
100
|
getOrCreateContext<C>(contextIdentifier: ContextIdentifier | null): Promise<StoredContext<C>>;
|
|
62
101
|
getContext<C>(contextIdentifier: ContextIdentifier): Promise<StoredContext<C> | null>;
|
|
63
102
|
updateContextContent<C>(contextIdentifier: ContextIdentifier, content: C): Promise<StoredContext<C>>;
|
|
103
|
+
updateContextDefinition<C>(contextIdentifier: ContextIdentifier, definition: {
|
|
104
|
+
description?: string | null;
|
|
105
|
+
goal?: string | null;
|
|
106
|
+
}): Promise<StoredContext<C>>;
|
|
107
|
+
upsertContextResources(contextIdentifier: ContextIdentifier, resources: ContextResource[]): Promise<StoredContextResource[]>;
|
|
108
|
+
getContextResources(contextIdentifier: ContextIdentifier): Promise<StoredContextResource[]>;
|
|
64
109
|
updateContextReactor<C>(contextIdentifier: ContextIdentifier, reactor: {
|
|
65
110
|
kind: string;
|
|
66
111
|
state?: Record<string, unknown> | null;
|
|
@@ -80,7 +125,7 @@ export interface ContextStore {
|
|
|
80
125
|
}): Promise<{
|
|
81
126
|
id: string;
|
|
82
127
|
}>;
|
|
83
|
-
updateStep(stepId: string, patch: Partial<Pick<ContextStep, "status" | "
|
|
128
|
+
updateStep(stepId: string, patch: Partial<Pick<ContextStep, "status" | "errorText" | "updatedAt">>): Promise<void>;
|
|
84
129
|
saveStepParts(params: {
|
|
85
130
|
stepId: string;
|
|
86
131
|
parts: any[];
|
package/dist/context.stream.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContextStatus, ExecutionStatus, ItemStatus, ItemType,
|
|
1
|
+
import type { ContextStatus, ExecutionStatus, ItemStatus, ItemType, StepStatus, ContextStreamChunkType } from "./context.contract.js";
|
|
2
2
|
type IsoDateString = string;
|
|
3
3
|
type ContextStreamEventBase = {
|
|
4
4
|
type: string;
|
|
@@ -23,6 +23,14 @@ export type ContextContentUpdatedEvent = ContextStreamEventBase & {
|
|
|
23
23
|
type: "context.content_updated";
|
|
24
24
|
contextId: string;
|
|
25
25
|
};
|
|
26
|
+
export type ContextDefinitionUpdatedEvent = ContextStreamEventBase & {
|
|
27
|
+
type: "context.definition_updated";
|
|
28
|
+
contextId: string;
|
|
29
|
+
};
|
|
30
|
+
export type ContextResourcesUpdatedEvent = ContextStreamEventBase & {
|
|
31
|
+
type: "context.resources_updated";
|
|
32
|
+
contextId: string;
|
|
33
|
+
};
|
|
26
34
|
export type ExecutionCreatedEvent = ContextStreamEventBase & {
|
|
27
35
|
type: "execution.created";
|
|
28
36
|
executionId: string;
|
|
@@ -83,8 +91,6 @@ export type StepUpdatedEvent = ContextStreamEventBase & {
|
|
|
83
91
|
executionId: string;
|
|
84
92
|
iteration?: number;
|
|
85
93
|
status?: StepStatus;
|
|
86
|
-
kind?: StepKind;
|
|
87
|
-
actionName?: string;
|
|
88
94
|
};
|
|
89
95
|
export type StepCompletedEvent = ContextStreamEventBase & {
|
|
90
96
|
type: "step.completed";
|
|
@@ -129,6 +135,10 @@ export type ChunkEmittedEvent = ContextStreamEventBase & {
|
|
|
129
135
|
stepId?: string;
|
|
130
136
|
itemId?: string;
|
|
131
137
|
partKey?: string;
|
|
138
|
+
partId?: string;
|
|
139
|
+
providerPartId?: string;
|
|
140
|
+
partType?: string;
|
|
141
|
+
partSlot?: string;
|
|
132
142
|
actionRef?: string;
|
|
133
143
|
provider?: string;
|
|
134
144
|
providerChunkType?: string;
|
|
@@ -136,7 +146,7 @@ export type ChunkEmittedEvent = ContextStreamEventBase & {
|
|
|
136
146
|
data?: unknown;
|
|
137
147
|
raw?: unknown;
|
|
138
148
|
};
|
|
139
|
-
export type ContextLifecycleEvent = ContextCreatedEvent | ContextResolvedEvent | ContextStatusChangedEvent | ContextContentUpdatedEvent;
|
|
149
|
+
export type ContextLifecycleEvent = ContextCreatedEvent | ContextResolvedEvent | ContextStatusChangedEvent | ContextContentUpdatedEvent | ContextDefinitionUpdatedEvent | ContextResourcesUpdatedEvent;
|
|
140
150
|
export type ExecutionEvent = ExecutionCreatedEvent | ExecutionCompletedEvent | ExecutionFailedEvent;
|
|
141
151
|
export type ItemEvent = ItemCreatedEvent | ItemUpdatedEvent | ItemPendingEvent | ItemCompletedEvent;
|
|
142
152
|
export type StepEvent = StepCreatedEvent | StepUpdatedEvent | StepCompletedEvent | StepFailedEvent;
|
package/dist/context.stream.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isContextStreamChunkType } from "./context.contract.js";
|
|
2
|
+
import { assertValidContextPartChunkIdentity } from "./context.part-identity.js";
|
|
2
3
|
function assertObject(value, label) {
|
|
3
4
|
if (!value || typeof value !== "object") {
|
|
4
5
|
throw new Error(`Invalid ${label}: expected object.`);
|
|
@@ -14,6 +15,12 @@ function assertNumber(value, label) {
|
|
|
14
15
|
throw new Error(`Invalid ${label}: expected number.`);
|
|
15
16
|
}
|
|
16
17
|
}
|
|
18
|
+
function assertPositiveInteger(value, label) {
|
|
19
|
+
assertNumber(value, label);
|
|
20
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
21
|
+
throw new Error(`Invalid ${label}: expected positive integer.`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
17
24
|
function assertOptionalString(value, label) {
|
|
18
25
|
if (value !== undefined) {
|
|
19
26
|
assertString(value, label);
|
|
@@ -41,6 +48,14 @@ export function parseContextStreamEvent(value) {
|
|
|
41
48
|
assertString(value.contextId, `${type}.contextId`);
|
|
42
49
|
return value;
|
|
43
50
|
}
|
|
51
|
+
case "context.definition_updated": {
|
|
52
|
+
assertString(value.contextId, `${type}.contextId`);
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
case "context.resources_updated": {
|
|
56
|
+
assertString(value.contextId, `${type}.contextId`);
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
44
59
|
case "execution.created":
|
|
45
60
|
case "execution.completed":
|
|
46
61
|
case "execution.failed": {
|
|
@@ -85,8 +100,6 @@ export function parseContextStreamEvent(value) {
|
|
|
85
100
|
if (value.iteration !== undefined)
|
|
86
101
|
assertNumber(value.iteration, `${type}.iteration`);
|
|
87
102
|
assertOptionalString(value.status, `${type}.status`);
|
|
88
|
-
assertOptionalString(value.kind, `${type}.kind`);
|
|
89
|
-
assertOptionalString(value.actionName, `${type}.actionName`);
|
|
90
103
|
return value;
|
|
91
104
|
}
|
|
92
105
|
case "step.completed":
|
|
@@ -121,10 +134,25 @@ export function parseContextStreamEvent(value) {
|
|
|
121
134
|
assertOptionalString(value.stepId, `${type}.stepId`);
|
|
122
135
|
assertOptionalString(value.itemId, `${type}.itemId`);
|
|
123
136
|
assertOptionalString(value.partKey, `${type}.partKey`);
|
|
137
|
+
assertOptionalString(value.partId, `${type}.partId`);
|
|
138
|
+
assertOptionalString(value.providerPartId, `${type}.providerPartId`);
|
|
139
|
+
assertOptionalString(value.partType, `${type}.partType`);
|
|
140
|
+
assertOptionalString(value.partSlot, `${type}.partSlot`);
|
|
124
141
|
assertOptionalString(value.actionRef, `${type}.actionRef`);
|
|
125
142
|
assertOptionalString(value.provider, `${type}.provider`);
|
|
126
143
|
assertOptionalString(value.providerChunkType, `${type}.providerChunkType`);
|
|
127
|
-
|
|
144
|
+
assertPositiveInteger(value.sequence, `${type}.sequence`);
|
|
145
|
+
assertValidContextPartChunkIdentity({
|
|
146
|
+
label: type,
|
|
147
|
+
chunkType: value.chunkType,
|
|
148
|
+
stepId: typeof value.stepId === "string" ? value.stepId : undefined,
|
|
149
|
+
partId: typeof value.partId === "string" ? value.partId : undefined,
|
|
150
|
+
provider: typeof value.provider === "string" ? value.provider : undefined,
|
|
151
|
+
providerPartId: typeof value.providerPartId === "string" ? value.providerPartId : undefined,
|
|
152
|
+
partType: typeof value.partType === "string" ? value.partType : undefined,
|
|
153
|
+
partSlot: typeof value.partSlot === "string" ? value.partSlot : undefined,
|
|
154
|
+
actionRef: typeof value.actionRef === "string" ? value.actionRef : undefined,
|
|
155
|
+
});
|
|
128
156
|
return value;
|
|
129
157
|
}
|
|
130
158
|
default:
|
package/dist/domain.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { eventsDomain } from "./schema.js";
|
package/dist/domain.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { eventsDomain } from "./schema.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
export { context, createContext, createAiSdkReactor, createScriptedReactor, type CreateAiSdkReactorOptions, type CreateScriptedReactorOptions, type ScriptedReactorStep, type ContextConfig, type ContextInstance, type ContextOptions, type ContextStreamOptions, type ContextReactor, type ContextReactorParams, type ContextReactionResult, type ContextActionRequest, type ContextReactionLLM, ContextEngine, type RegistrableContextBuilder, type ContextReactParams, type ContextReactResult, type ContextWorkflowRun, type ContextDurableWorkflowPayload, type ContextDurableWorkflowFunction, type ContextModelInit, type ContextTool, type ContextToolExecuteContext, runContextReactionDirect, } from "./context.js";
|
|
2
|
-
export type { ContextStore, ContextIdentifier, StoredContext, ContextItem, ContextExecution, } from "./context.store.js";
|
|
1
|
+
export { context, createContext, createAiSdkReactor, createScriptedReactor, type CreateAiSdkReactorOptions, type CreateScriptedReactorOptions, type ScriptedReactorStep, type ContextConfig, type ContextResourcesParams, type ContextInstance, type ContextOptions, type ContextStreamOptions, type ContextReactor, type ContextReactorParams, type ContextReactionResult, type ContextActionRequest, type ContextReactionLLM, ContextEngine, defineAction, action, type RegistrableContextBuilder, type ContextReactParams, type ContextDirectReactParams, type ContextDurableReactParams, type ContextReactResult, type ContextReactBase, type ContextReactFinalResult, type ContextDirectRun, type ContextReactRun, type ContextWorkflowRun, type ContextDurableWorkflowPayload, type ContextDurableWorkflowFunction, type ContextModelInit, type ContextTool, type ContextAction, type ContextActionBase, type ContextActionExecuteParams, type AnyContextAction, type ContextActionDefinition, type DefineContextActionDefinition, type DefineContextActionExecute, type LegacyContextActionDefinition, type LegacyContextActionExecute, type ContextActionExecute, type ContextActionInput, type ContextActionOutput, type ContextProviderDefinedAction, type ContextActionSchema, type ContextToolExecuteContext, runContextReactionDirect, } from "./context.js";
|
|
2
|
+
export type { ContextStore, ContextIdentifier, StoredContext, ContextResource, ContextResourceBase, ContextFileResource, ContextLinkResource, ContextRepositoryResource, ContextDatasetResource, ContextExternalResource, StoredContextResource, ContextItem, ContextExecution, } from "./context.store.js";
|
|
3
3
|
export type { WireDate, ContextMirrorContext, ContextMirrorExecution, ContextMirrorWrite, ContextMirrorRequest, } from "./mirror.js";
|
|
4
4
|
export { registerContext, getContext, getContextFactory, hasContext, listContexts, type ContextKey, } from "./context.registry.js";
|
|
5
5
|
export { eventsDomain } from "./schema.js";
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
6
|
+
export { didActionExecute, extractActionCallsFromParts, type ContextActionCall, } from "./context.action-calls.js";
|
|
7
|
+
export { actionsToActionSpecs, actionSpecToAiSdkTool, type SerializableActionSpec, type SerializableFunctionActionSpec, type SerializableProviderDefinedActionSpec, } from "./tools-to-model-tools.js";
|
|
8
|
+
export { reactorMetadataSchema, contextPartSchema, contextPartEnvelopeSchema, contextPartContentSchema, contextMessagePartSchema, contextReasoningPartSchema, contextSourcePartSchema, contextActionPartSchema, contextEnginePartSchema, createContextPartSchema, parseContextPart, isContextPartEnvelope, parseContextPartEnvelope, normalizePartsForPersistence, } from "./context.parts.js";
|
|
9
|
+
export type { ReactorMetadata, ContextEnginePart, ContextActionPart, ContextActionStartedPart, ContextActionCompletedPart, ContextActionFailedPart, ContextPartActionMap, ContextPart, ContextPartEnvelope, ContextPartContent, ContextInlineContent, } from "./context.parts.js";
|
|
9
10
|
export { INPUT_ITEM_TYPE, INPUT_TEXT_ITEM_TYPE, OUTPUT_ITEM_TYPE, WEB_CHANNEL, AGENT_CHANNEL, EMAIL_CHANNEL, createUserItemFromUIMessages, createAssistantItemFromUIMessages, convertToUIMessage, convertItemToModelMessages, convertItemsToModelMessages, convertModelMessageToItem, isContextOutputPart, normalizeContextOutputPart, type ResponseMessage, type ContextOutputPart, type ContextOutputContentPart, } from "./context.events.js";
|
|
10
|
-
export { CONTEXT_STATUSES, EXECUTION_STATUSES, STEP_STATUSES,
|
|
11
|
-
export type { Transition, ContextStatus, ExecutionStatus, StepStatus,
|
|
11
|
+
export { CONTEXT_STATUSES, EXECUTION_STATUSES, STEP_STATUSES, ITEM_STATUSES, ITEM_TYPES, CHANNELS, TRACE_EVENT_KINDS, CONTEXT_STREAM_CHUNK_TYPES, STREAM_LIFECYCLE_CHUNK_TYPES, STREAM_TEXT_CHUNK_TYPES, STREAM_REASONING_CHUNK_TYPES, STREAM_ACTION_CHUNK_TYPES, STREAM_SOURCE_CHUNK_TYPES, STREAM_METADATA_CHUNK_TYPES, STREAM_ERROR_CHUNK_TYPES, CONTEXT_TRANSITIONS, EXECUTION_TRANSITIONS, STEP_TRANSITIONS, ITEM_TRANSITIONS, canContextTransition, canExecutionTransition, canStepTransition, canItemTransition, assertContextTransition, assertExecutionTransition, assertStepTransition, assertItemTransition, isContextStreamChunkType, assertContextPartKey, } from "./context.contract.js";
|
|
12
|
+
export type { Transition, ContextStatus, ExecutionStatus, StepStatus, ItemStatus, ItemType, Channel, TraceEventKind, ContextStreamChunkType, ContextTransition, ExecutionTransition, StepTransition, ItemTransition, } from "./context.contract.js";
|
|
12
13
|
export { DEFAULT_CODEX_TOOL_NAME, DEFAULT_CODEX_MODEL, codexToolInputSchema, buildDefaultCodexNarrative, didCodexToolExecute, createCodexContextBuilder, type CodexContextRuntimeMode, type CodexContextReasoningLevel, type CodexContextRuntime, type CodexContextEnv, type CodexToolInput, type CodexToolOutput, type CodexExecuteArgs, type CodexContextBuilderConfig, type CodexContextBuilder, } from "./codex.js";
|
|
13
|
-
export { useContext, type ContextSnapshot, type ContextStreamChunk, type UseContextOptions, } from "./react.js";
|
|
14
14
|
export { parseContextStreamEvent, assertContextStreamTransitions, validateContextStreamTimeline, } from "./context.stream.js";
|
|
15
|
-
export { CONTEXT_STEP_STREAM_VERSION, createContextStepStreamChunk, parseContextStepStreamChunk, encodeContextStepStreamChunk, } from "./context.step-stream.js";
|
|
16
|
-
export type {
|
|
15
|
+
export { CONTEXT_STEP_STREAM_VERSION, createContextStepStreamChunk, validateContextStepStreamChunk, parseContextStepStreamChunk, encodeContextStepStreamChunk, } from "./context.step-stream.js";
|
|
16
|
+
export type { ContextStepStreamChunkValidationOptions, } from "./context.step-stream.js";
|
|
17
|
+
export { CONTEXT_PART_ID_NAMESPACE, CONTEXT_PART_UUID_RE, CONTEXT_STREAM_PART_TYPES, assertValidContextPartChunkIdentity, resolveContextPartChunkDescriptor, resolveContextPartChunkIdentity, resolveContextPartId, resolveContextStreamPartSlot, resolveContextStreamPartType, uuidV5, } from "./context.part-identity.js";
|
|
18
|
+
export type { ContextPartChunkDescriptor, ContextPartChunkIdentity, ContextPartChunkIdentityInput, ContextPartChunkValidationInput, ContextStreamPartSlot, ContextStreamPartType, } from "./context.part-identity.js";
|
|
19
|
+
export type { ContextStreamEvent, ContextCreatedEvent, ContextResolvedEvent, ContextStatusChangedEvent, ContextContentUpdatedEvent, ContextDefinitionUpdatedEvent, ContextResourcesUpdatedEvent, ExecutionCreatedEvent, ExecutionCompletedEvent, ExecutionFailedEvent, ItemCreatedEvent, ItemUpdatedEvent, ItemPendingEvent, ItemCompletedEvent, StepCreatedEvent, StepUpdatedEvent, StepCompletedEvent, StepFailedEvent, PartCreatedEvent, PartUpdatedEvent, ChunkEmittedEvent, } from "./context.stream.js";
|
|
17
20
|
export type { ContextStepStreamChunk } from "./context.step-stream.js";
|
|
18
21
|
export type { ContextSkillPackage, ContextSkillPackageFile } from "./context.skill.js";
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
export { context, createContext, createAiSdkReactor, createScriptedReactor, ContextEngine, runContextReactionDirect, } from "./context.js";
|
|
1
|
+
export { context, createContext, createAiSdkReactor, createScriptedReactor, ContextEngine, defineAction, action, runContextReactionDirect, } from "./context.js";
|
|
2
2
|
export { registerContext, getContext, getContextFactory, hasContext, listContexts, } from "./context.registry.js";
|
|
3
3
|
export { eventsDomain } from "./schema.js";
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
4
|
+
export { didActionExecute, extractActionCallsFromParts, } from "./context.action-calls.js";
|
|
5
|
+
export { actionsToActionSpecs, actionSpecToAiSdkTool, } from "./tools-to-model-tools.js";
|
|
6
|
+
export { reactorMetadataSchema, contextPartSchema, contextPartEnvelopeSchema, contextPartContentSchema, contextMessagePartSchema, contextReasoningPartSchema, contextSourcePartSchema, contextActionPartSchema, contextEnginePartSchema, createContextPartSchema, parseContextPart, isContextPartEnvelope, parseContextPartEnvelope, normalizePartsForPersistence, } from "./context.parts.js";
|
|
6
7
|
export { INPUT_ITEM_TYPE, INPUT_TEXT_ITEM_TYPE, OUTPUT_ITEM_TYPE, WEB_CHANNEL, AGENT_CHANNEL, EMAIL_CHANNEL, createUserItemFromUIMessages, createAssistantItemFromUIMessages, convertToUIMessage, convertItemToModelMessages, convertItemsToModelMessages, convertModelMessageToItem, isContextOutputPart, normalizeContextOutputPart, } from "./context.events.js";
|
|
7
|
-
export { CONTEXT_STATUSES, EXECUTION_STATUSES, STEP_STATUSES,
|
|
8
|
+
export { CONTEXT_STATUSES, EXECUTION_STATUSES, STEP_STATUSES, ITEM_STATUSES, ITEM_TYPES, CHANNELS, TRACE_EVENT_KINDS, CONTEXT_STREAM_CHUNK_TYPES, STREAM_LIFECYCLE_CHUNK_TYPES, STREAM_TEXT_CHUNK_TYPES, STREAM_REASONING_CHUNK_TYPES, STREAM_ACTION_CHUNK_TYPES, STREAM_SOURCE_CHUNK_TYPES, STREAM_METADATA_CHUNK_TYPES, STREAM_ERROR_CHUNK_TYPES, CONTEXT_TRANSITIONS, EXECUTION_TRANSITIONS, STEP_TRANSITIONS, ITEM_TRANSITIONS, canContextTransition, canExecutionTransition, canStepTransition, canItemTransition, assertContextTransition, assertExecutionTransition, assertStepTransition, assertItemTransition, isContextStreamChunkType, assertContextPartKey, } from "./context.contract.js";
|
|
8
9
|
export { DEFAULT_CODEX_TOOL_NAME, DEFAULT_CODEX_MODEL, codexToolInputSchema, buildDefaultCodexNarrative, didCodexToolExecute, createCodexContextBuilder, } from "./codex.js";
|
|
9
|
-
export { useContext, } from "./react.js";
|
|
10
10
|
export { parseContextStreamEvent, assertContextStreamTransitions, validateContextStreamTimeline, } from "./context.stream.js";
|
|
11
|
-
export { CONTEXT_STEP_STREAM_VERSION, createContextStepStreamChunk, parseContextStepStreamChunk, encodeContextStepStreamChunk, } from "./context.step-stream.js";
|
|
11
|
+
export { CONTEXT_STEP_STREAM_VERSION, createContextStepStreamChunk, validateContextStepStreamChunk, parseContextStepStreamChunk, encodeContextStepStreamChunk, } from "./context.step-stream.js";
|
|
12
|
+
export { CONTEXT_PART_ID_NAMESPACE, CONTEXT_PART_UUID_RE, CONTEXT_STREAM_PART_TYPES, assertValidContextPartChunkIdentity, resolveContextPartChunkDescriptor, resolveContextPartChunkIdentity, resolveContextPartId, resolveContextStreamPartSlot, resolveContextStreamPartType, uuidV5, } from "./context.part-identity.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type ActionStatus = "started" | "completed" | "failed";
|
|
2
|
+
export type ContextActionPartInfo = {
|
|
3
|
+
actionName: string;
|
|
4
|
+
actionCallId: string;
|
|
5
|
+
status: ActionStatus;
|
|
6
|
+
input?: unknown;
|
|
7
|
+
output?: unknown;
|
|
8
|
+
errorText?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function normalizeContextEventParts(parts: unknown[]): Record<string, unknown>[];
|
|
11
|
+
export declare function getActionPartInfo(part: unknown): ContextActionPartInfo | null;
|
|
12
|
+
export declare function getCreateMessageText(part: unknown): string;
|
|
13
|
+
export declare function getPartText(part: unknown): string;
|
|
14
|
+
export declare function getReasoningText(part: unknown): string;
|
|
15
|
+
export declare function getReasoningState(part: unknown): string;
|
|
16
|
+
export declare function getSourceParts(part: unknown): any[];
|
|
17
|
+
export declare function findNormalizedToolPart(parts: unknown[], toolName: string): Record<string, unknown> | null;
|
|
18
|
+
export {};
|