@moinulmoin/eden-runtime-cloudflare 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +0 -31
- package/dist/eden-eve-host-worker.mjs +1 -9
- package/dist/eve-host-runtime.d.ts +0 -1
- package/dist/eve-host-runtime.js +0 -1
- package/dist/eve-host.d.ts +2 -1
- package/dist/eve-host.js +2 -8
- package/dist/index.d.ts +0 -18
- package/dist/index.js +0 -5
- package/package.json +2 -6
- package/dist/artifact-runtime.d.ts +0 -27
- package/dist/artifact-runtime.js +0 -14
- package/dist/http-host.d.ts +0 -6
- package/dist/http-host.js +0 -419
- package/dist/model-adapter-internal.d.ts +0 -12
- package/dist/model-adapter-internal.js +0 -172
- package/dist/model-adapter.d.ts +0 -9
- package/dist/model-adapter.js +0 -56
- package/dist/model-contracts.d.ts +0 -92
- package/dist/model-contracts.js +0 -2
- package/dist/model-normalizers.d.ts +0 -7
- package/dist/model-normalizers.js +0 -453
- package/dist/session-checkpoint.d.ts +0 -48
- package/dist/session-checkpoint.js +0 -300
- package/dist/session-identity.d.ts +0 -9
- package/dist/session-identity.js +0 -45
- package/dist/session-jobs.d.ts +0 -69
- package/dist/session-jobs.js +0 -427
- package/dist/session-journal.d.ts +0 -154
- package/dist/session-journal.js +0 -391
- package/dist/session-schema.d.ts +0 -21
- package/dist/session-schema.js +0 -247
- package/dist/session-state.d.ts +0 -165
- package/dist/session-state.js +0 -168
- package/dist/session.d.ts +0 -40
- package/dist/session.js +0 -792
- package/dist/test-execution.d.ts +0 -8
- package/dist/test-execution.js +0 -12
- package/dist/test-worker.d.ts +0 -12
- package/dist/test-worker.js +0 -214
- package/dist/tool-harness.d.ts +0 -31
- package/dist/tool-harness.js +0 -226
- package/dist/turn-runner-storage.d.ts +0 -28
- package/dist/turn-runner-storage.js +0 -583
- package/dist/turn-runner-types.d.ts +0 -112
- package/dist/turn-runner-types.js +0 -21
- package/dist/turn-runner.d.ts +0 -6
- package/dist/turn-runner.js +0 -370
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { createModelAdapter, } from "./model-adapter.js";
|
|
2
|
-
function isRecord(value) {
|
|
3
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
-
}
|
|
5
|
-
function providerMessage(message) {
|
|
6
|
-
if (typeof message.content === "string") {
|
|
7
|
-
return { role: message.role, content: message.content };
|
|
8
|
-
}
|
|
9
|
-
if (message.role === "assistant") {
|
|
10
|
-
const text = message.content
|
|
11
|
-
.filter((part) => part.type === "text")
|
|
12
|
-
.map((part) => part.text)
|
|
13
|
-
.join("");
|
|
14
|
-
const toolCalls = message.content
|
|
15
|
-
.filter((part) => part.type === "tool-call")
|
|
16
|
-
.map((part) => ({
|
|
17
|
-
id: part.callId,
|
|
18
|
-
type: "function",
|
|
19
|
-
function: {
|
|
20
|
-
name: part.toolName,
|
|
21
|
-
arguments: JSON.stringify(part.input),
|
|
22
|
-
},
|
|
23
|
-
}));
|
|
24
|
-
return {
|
|
25
|
-
role: message.role,
|
|
26
|
-
content: text.length === 0 ? null : text,
|
|
27
|
-
...(toolCalls.length === 0 ? {} : { tool_calls: toolCalls }),
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
if (message.role === "tool") {
|
|
31
|
-
return {
|
|
32
|
-
role: "tool",
|
|
33
|
-
content: message.content
|
|
34
|
-
.filter((part) => part.type === "tool-result")
|
|
35
|
-
.map((part) => JSON.stringify(part.output))
|
|
36
|
-
.join("\n"),
|
|
37
|
-
tool_call_id: message.content.find((part) => part.type === "tool-result")?.callId,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
role: message.role,
|
|
42
|
-
content: message.content
|
|
43
|
-
.filter((part) => part.type === "text")
|
|
44
|
-
.map((part) => part.text)
|
|
45
|
-
.join(""),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function providerTools(tools) {
|
|
49
|
-
if (tools === undefined)
|
|
50
|
-
return undefined;
|
|
51
|
-
return tools.map((tool) => ({
|
|
52
|
-
type: "function",
|
|
53
|
-
function: {
|
|
54
|
-
name: tool.name,
|
|
55
|
-
description: tool.description,
|
|
56
|
-
parameters: isRecord(tool.inputSchema)
|
|
57
|
-
? tool.inputSchema
|
|
58
|
-
: { type: "object", properties: {} },
|
|
59
|
-
},
|
|
60
|
-
}));
|
|
61
|
-
}
|
|
62
|
-
function providerToolChoice(choice) {
|
|
63
|
-
if (choice === undefined || choice === "auto" || choice === "none") {
|
|
64
|
-
return choice;
|
|
65
|
-
}
|
|
66
|
-
if (choice === "required")
|
|
67
|
-
return "required";
|
|
68
|
-
return {
|
|
69
|
-
type: "function",
|
|
70
|
-
function: { name: choice.toolName },
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
function parseToolInput(value) {
|
|
74
|
-
if (typeof value !== "string")
|
|
75
|
-
return value;
|
|
76
|
-
try {
|
|
77
|
-
return JSON.parse(value);
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
return {};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function normalizeWorkersAIResult(value) {
|
|
84
|
-
if (!isRecord(value))
|
|
85
|
-
return {};
|
|
86
|
-
const choices = Array.isArray(value.choices) ? value.choices : [];
|
|
87
|
-
const choice = isRecord(choices[0]) ? choices[0] : {};
|
|
88
|
-
const message = isRecord(choice.message) ? choice.message : {};
|
|
89
|
-
const toolCalls = Array.isArray(message.tool_calls)
|
|
90
|
-
? message.tool_calls
|
|
91
|
-
.filter(isRecord)
|
|
92
|
-
.map((call, index) => {
|
|
93
|
-
const functionValue = isRecord(call.function) ? call.function : {};
|
|
94
|
-
return {
|
|
95
|
-
callId: typeof call.id === "string" ? call.id : `call_${index + 1}`,
|
|
96
|
-
toolName: typeof functionValue.name === "string"
|
|
97
|
-
? functionValue.name
|
|
98
|
-
: "",
|
|
99
|
-
input: parseToolInput(functionValue.arguments),
|
|
100
|
-
};
|
|
101
|
-
})
|
|
102
|
-
: [];
|
|
103
|
-
const usage = isRecord(value.usage)
|
|
104
|
-
? {
|
|
105
|
-
...(typeof value.usage.prompt_tokens === "number"
|
|
106
|
-
? { inputTokens: value.usage.prompt_tokens }
|
|
107
|
-
: typeof value.usage.input_tokens === "number"
|
|
108
|
-
? { inputTokens: value.usage.input_tokens }
|
|
109
|
-
: {}),
|
|
110
|
-
...(typeof value.usage.completion_tokens === "number"
|
|
111
|
-
? { outputTokens: value.usage.completion_tokens }
|
|
112
|
-
: typeof value.usage.output_tokens === "number"
|
|
113
|
-
? { outputTokens: value.usage.output_tokens }
|
|
114
|
-
: {}),
|
|
115
|
-
...(typeof value.usage.total_tokens === "number"
|
|
116
|
-
? { totalTokens: value.usage.total_tokens }
|
|
117
|
-
: {}),
|
|
118
|
-
}
|
|
119
|
-
: undefined;
|
|
120
|
-
return {
|
|
121
|
-
text: typeof message.content === "string" ? message.content : "",
|
|
122
|
-
calls: toolCalls,
|
|
123
|
-
results: [],
|
|
124
|
-
finishReason: choice.finish_reason,
|
|
125
|
-
...(usage === undefined ? {} : { usage }),
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
function createWorkersAIProvider(options) {
|
|
129
|
-
return {
|
|
130
|
-
call: async (request) => {
|
|
131
|
-
const modelId = request.modelId ?? options.modelId;
|
|
132
|
-
const generationOptions = request.options;
|
|
133
|
-
const tools = providerTools(request.tools);
|
|
134
|
-
const inputs = {
|
|
135
|
-
messages: request.messages.map(providerMessage),
|
|
136
|
-
...(tools === undefined
|
|
137
|
-
? {}
|
|
138
|
-
: { tools }),
|
|
139
|
-
...(request.toolChoice === undefined
|
|
140
|
-
? {}
|
|
141
|
-
: { tool_choice: providerToolChoice(request.toolChoice) }),
|
|
142
|
-
...(generationOptions?.temperature === undefined
|
|
143
|
-
? {}
|
|
144
|
-
: { temperature: generationOptions.temperature }),
|
|
145
|
-
...(generationOptions?.maxOutputTokens === undefined
|
|
146
|
-
? {}
|
|
147
|
-
: { max_tokens: generationOptions.maxOutputTokens }),
|
|
148
|
-
...(generationOptions?.thinking === false
|
|
149
|
-
? { reasoning_effort: null }
|
|
150
|
-
: {}),
|
|
151
|
-
};
|
|
152
|
-
const binding = options.binding;
|
|
153
|
-
const response = await binding.run(modelId, inputs, {
|
|
154
|
-
gateway: { id: options.gatewayId },
|
|
155
|
-
...(request.signal === undefined ? {} : { signal: request.signal }),
|
|
156
|
-
});
|
|
157
|
-
if (response instanceof Response) {
|
|
158
|
-
return normalizeWorkersAIResult(await response.json());
|
|
159
|
-
}
|
|
160
|
-
return normalizeWorkersAIResult(response);
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
/** Internal only. The public runtime contract never accepts a binding. */
|
|
165
|
-
export function createWorkersAIModelProvider(options) {
|
|
166
|
-
return createWorkersAIProvider(options).call;
|
|
167
|
-
}
|
|
168
|
-
/** Internal only. The public runtime contract never accepts a binding. */
|
|
169
|
-
export function createWorkersAIModelAdapter(options) {
|
|
170
|
-
return createModelAdapter(createWorkersAIModelProvider(options));
|
|
171
|
-
}
|
|
172
|
-
//# sourceMappingURL=model-adapter-internal.js.map
|
package/dist/model-adapter.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { EdenModelOutcome, EdenModelAdapterRequest, EdenModelRequest } from "./model-contracts.js";
|
|
2
|
-
export type { EdenModelCorrelation, EdenModelFailure, EdenModelFailureCode, EdenModelFinishReason, EdenModelMessage, EdenModelMessagePart, EdenModelOptions, EdenModelOutcome, EdenModelAdapterRequest, EdenModelRequest, EdenModelResult, EdenModelRole, EdenModelToolCall, EdenModelToolChoice, EdenModelToolDefinition, EdenModelToolResult, EdenModelUsage, } from "./model-contracts.js";
|
|
3
|
-
export { normalizeEdenJsonValue, normalizeModelFailure, normalizeModelMessages, normalizeModelResult, } from "./model-normalizers.js";
|
|
4
|
-
export type EdenModelAdapterCall = (request: EdenModelAdapterRequest) => Promise<unknown>;
|
|
5
|
-
export interface EdenModelAdapter {
|
|
6
|
-
readonly call: (request: EdenModelRequest) => Promise<EdenModelOutcome>;
|
|
7
|
-
}
|
|
8
|
-
export declare function createModelAdapter(provider: EdenModelAdapterCall): EdenModelAdapter;
|
|
9
|
-
//# sourceMappingURL=model-adapter.d.ts.map
|
package/dist/model-adapter.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { normalizeModelFailure, normalizeModelMessages, normalizeModelResult, } from "./model-normalizers.js";
|
|
2
|
-
export { normalizeEdenJsonValue, normalizeModelFailure, normalizeModelMessages, normalizeModelResult, } from "./model-normalizers.js";
|
|
3
|
-
function normalizeToolDefinition(tool) {
|
|
4
|
-
return {
|
|
5
|
-
name: tool.name,
|
|
6
|
-
description: tool.description,
|
|
7
|
-
inputSchema: tool.inputSchema,
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
function providerRequest(request) {
|
|
11
|
-
const messages = normalizeModelMessages(request.messages);
|
|
12
|
-
const tools = request.tools === undefined
|
|
13
|
-
? undefined
|
|
14
|
-
: request.tools.map(normalizeToolDefinition);
|
|
15
|
-
return {
|
|
16
|
-
messages,
|
|
17
|
-
...(request.modelId === undefined ? {} : { modelId: request.modelId }),
|
|
18
|
-
...(tools === undefined ? {} : { tools }),
|
|
19
|
-
...(request.toolChoice === undefined
|
|
20
|
-
? {}
|
|
21
|
-
: { toolChoice: request.toolChoice }),
|
|
22
|
-
...(request.options === undefined ? {} : { options: request.options }),
|
|
23
|
-
...(request.signal === undefined ? {} : { signal: request.signal }),
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export function createModelAdapter(provider) {
|
|
27
|
-
return {
|
|
28
|
-
async call(request) {
|
|
29
|
-
const correlation = request.correlation;
|
|
30
|
-
try {
|
|
31
|
-
const value = await provider(providerRequest(request));
|
|
32
|
-
let result;
|
|
33
|
-
try {
|
|
34
|
-
result = normalizeModelResult(value, correlation);
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
return {
|
|
38
|
-
status: "error",
|
|
39
|
-
error: normalizeModelFailure(error, correlation, "model_result_invalid"),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return { status: "ok", result };
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
const code = request.signal?.aborted
|
|
46
|
-
? "model_call_aborted"
|
|
47
|
-
: "model_call_failed";
|
|
48
|
-
return {
|
|
49
|
-
status: "error",
|
|
50
|
-
error: normalizeModelFailure(error, correlation, code),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=model-adapter.js.map
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type { EdenJsonValue, EdenModelOptions } from "@moinulmoin/eden-definitions";
|
|
2
|
-
export type { EdenModelOptions } from "@moinulmoin/eden-definitions";
|
|
3
|
-
export type EdenModelRole = "system" | "user" | "assistant" | "tool";
|
|
4
|
-
export interface EdenModelCorrelation {
|
|
5
|
-
readonly requestId: string;
|
|
6
|
-
readonly sessionId?: string;
|
|
7
|
-
readonly turnId?: string;
|
|
8
|
-
readonly stepId?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface EdenModelToolCall {
|
|
11
|
-
readonly callId: string;
|
|
12
|
-
readonly toolName: string;
|
|
13
|
-
readonly input: EdenJsonValue;
|
|
14
|
-
}
|
|
15
|
-
export interface EdenModelToolResult {
|
|
16
|
-
readonly callId: string;
|
|
17
|
-
readonly toolName: string;
|
|
18
|
-
readonly output: EdenJsonValue;
|
|
19
|
-
}
|
|
20
|
-
export type EdenModelMessagePart = {
|
|
21
|
-
readonly type: "text";
|
|
22
|
-
readonly text: string;
|
|
23
|
-
} | {
|
|
24
|
-
readonly type: "tool-call";
|
|
25
|
-
readonly callId: string;
|
|
26
|
-
readonly toolName: string;
|
|
27
|
-
readonly input: EdenJsonValue;
|
|
28
|
-
} | {
|
|
29
|
-
readonly type: "tool-result";
|
|
30
|
-
readonly callId: string;
|
|
31
|
-
readonly toolName: string;
|
|
32
|
-
readonly output: EdenJsonValue;
|
|
33
|
-
};
|
|
34
|
-
export interface EdenModelMessage {
|
|
35
|
-
readonly role: EdenModelRole;
|
|
36
|
-
readonly content: string | readonly EdenModelMessagePart[];
|
|
37
|
-
}
|
|
38
|
-
export interface EdenModelToolDefinition {
|
|
39
|
-
readonly name: string;
|
|
40
|
-
readonly description: string;
|
|
41
|
-
readonly inputSchema: EdenJsonValue;
|
|
42
|
-
}
|
|
43
|
-
export type EdenModelToolChoice = "auto" | "none" | "required" | {
|
|
44
|
-
readonly type: "tool";
|
|
45
|
-
readonly toolName: string;
|
|
46
|
-
};
|
|
47
|
-
export interface EdenModelAdapterRequest {
|
|
48
|
-
readonly modelId?: string;
|
|
49
|
-
readonly messages: readonly EdenModelMessage[];
|
|
50
|
-
readonly tools?: readonly EdenModelToolDefinition[];
|
|
51
|
-
readonly toolChoice?: EdenModelToolChoice;
|
|
52
|
-
readonly options?: EdenModelOptions;
|
|
53
|
-
readonly signal?: AbortSignal;
|
|
54
|
-
}
|
|
55
|
-
export interface EdenModelRequest {
|
|
56
|
-
readonly modelId?: string;
|
|
57
|
-
readonly messages: readonly EdenModelMessage[];
|
|
58
|
-
readonly tools?: readonly EdenModelToolDefinition[];
|
|
59
|
-
readonly toolChoice?: EdenModelToolChoice;
|
|
60
|
-
readonly options?: EdenModelOptions;
|
|
61
|
-
readonly correlation: EdenModelCorrelation;
|
|
62
|
-
readonly signal?: AbortSignal;
|
|
63
|
-
}
|
|
64
|
-
export type EdenModelFinishReason = "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other";
|
|
65
|
-
export interface EdenModelUsage {
|
|
66
|
-
readonly inputTokens?: number;
|
|
67
|
-
readonly outputTokens?: number;
|
|
68
|
-
readonly totalTokens?: number;
|
|
69
|
-
}
|
|
70
|
-
export interface EdenModelResult {
|
|
71
|
-
readonly text: string;
|
|
72
|
-
readonly calls: readonly EdenModelToolCall[];
|
|
73
|
-
readonly results: readonly EdenModelToolResult[];
|
|
74
|
-
readonly finishReason: EdenModelFinishReason;
|
|
75
|
-
readonly usage?: EdenModelUsage;
|
|
76
|
-
readonly correlation: EdenModelCorrelation;
|
|
77
|
-
}
|
|
78
|
-
export type EdenModelFailureCode = "model_call_aborted" | "model_call_failed" | "model_result_invalid";
|
|
79
|
-
export interface EdenModelFailure {
|
|
80
|
-
readonly code: EdenModelFailureCode;
|
|
81
|
-
readonly message: string;
|
|
82
|
-
readonly retryable: boolean;
|
|
83
|
-
readonly correlation: EdenModelCorrelation;
|
|
84
|
-
}
|
|
85
|
-
export type EdenModelOutcome = {
|
|
86
|
-
readonly status: "ok";
|
|
87
|
-
readonly result: EdenModelResult;
|
|
88
|
-
} | {
|
|
89
|
-
readonly status: "error";
|
|
90
|
-
readonly error: EdenModelFailure;
|
|
91
|
-
};
|
|
92
|
-
//# sourceMappingURL=model-contracts.d.ts.map
|
package/dist/model-contracts.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { EdenJsonValue } from "@moinulmoin/eden-definitions";
|
|
2
|
-
import type { EdenModelCorrelation, EdenModelFailure, EdenModelFailureCode, EdenModelMessage, EdenModelResult } from "./model-contracts.js";
|
|
3
|
-
export declare function normalizeEdenJsonValue(value: unknown): EdenJsonValue | undefined;
|
|
4
|
-
export declare function normalizeModelMessages(messages: readonly unknown[]): readonly EdenModelMessage[];
|
|
5
|
-
export declare function normalizeModelResult(providerResult: unknown, correlation: EdenModelCorrelation): EdenModelResult;
|
|
6
|
-
export declare function normalizeModelFailure(error: unknown, correlation: EdenModelCorrelation, code?: EdenModelFailureCode): EdenModelFailure;
|
|
7
|
-
//# sourceMappingURL=model-normalizers.d.ts.map
|