@flue/sdk 0.4.1 → 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.
- package/README.md +44 -42
- package/dist/app.d.mts +2 -2
- package/dist/app.mjs +2 -2
- package/dist/client.d.mts +7 -3
- package/dist/client.mjs +86 -14
- package/dist/cloudflare/index.d.mts +1 -1
- package/dist/cloudflare/index.mjs +2 -2
- package/dist/{flue-app-CG8i4wNG.d.mts → flue-app-O4_iqLkn.d.mts} +69 -4
- package/dist/{flue-app-DeTOZjPs.mjs → flue-app-SjL4I83Y.mjs} +520 -112
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +56 -6
- package/dist/internal.d.mts +40 -3
- package/dist/internal.mjs +284 -5
- package/dist/{mcp-C3UBXVkR.d.mts → mcp-BfcWmA-A.d.mts} +1 -1
- package/dist/{mcp-DM6yv_Qc.mjs → mcp-DwLSoSxp.mjs} +52 -38
- package/dist/node/index.d.mts +1 -1
- package/dist/{providers-DeFRIwp0.mjs → providers-BjEEoKLy.mjs} +11 -1
- package/dist/sandbox.d.mts +1 -1
- package/dist/sandbox.mjs +2 -2
- package/dist/{session-CFOByKnM.mjs → session-CRFfAJDq.mjs} +201 -79
- package/dist/{types-BAmV4f3Q.d.mts → types-Cdcq_ET2.d.mts} +87 -32
- package/package.json +2 -1
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { u as discoverSessionContext } from "./result-K1IRhWKM.mjs";
|
|
2
2
|
import { n as createCallHandle } from "./abort-Bg3qsAkU.mjs";
|
|
3
|
-
import { a as assertRoleExists, n as Session, r as deleteSessionTree } from "./session-
|
|
3
|
+
import { a as assertRoleExists, n as Session, r as deleteSessionTree } from "./session-CRFfAJDq.mjs";
|
|
4
4
|
import { createCwdSessionEnv, createFlueFs } from "./sandbox.mjs";
|
|
5
5
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
6
6
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
7
7
|
|
|
8
|
-
//#region src/
|
|
9
|
-
const
|
|
10
|
-
var
|
|
8
|
+
//#region src/harness.ts
|
|
9
|
+
const DEFAULT_SESSION_NAME = "default";
|
|
10
|
+
var Harness = class {
|
|
11
11
|
sessions = {
|
|
12
|
-
get: (
|
|
13
|
-
create: (
|
|
14
|
-
delete: (
|
|
12
|
+
get: (name, options) => this.openSession(name, "get", options),
|
|
13
|
+
create: (name, options) => this.openSession(name, "create", options),
|
|
14
|
+
delete: (name) => this.deleteSession(name)
|
|
15
15
|
};
|
|
16
16
|
fs;
|
|
17
17
|
openSessions = /* @__PURE__ */ new Map();
|
|
18
|
-
constructor(
|
|
19
|
-
this.
|
|
18
|
+
constructor(instanceId, name, config, env, store, eventCallback, agentTools = []) {
|
|
19
|
+
this.instanceId = instanceId;
|
|
20
|
+
this.name = name;
|
|
20
21
|
this.config = config;
|
|
21
22
|
this.env = env;
|
|
22
23
|
this.store = store;
|
|
@@ -24,8 +25,8 @@ var AgentClient = class {
|
|
|
24
25
|
this.agentTools = agentTools;
|
|
25
26
|
this.fs = createFlueFs(env);
|
|
26
27
|
}
|
|
27
|
-
async session(
|
|
28
|
-
return this.openSession(
|
|
28
|
+
async session(name, options) {
|
|
29
|
+
return this.openSession(name, "get-or-create", options);
|
|
29
30
|
}
|
|
30
31
|
shell(command, options) {
|
|
31
32
|
return createCallHandle(options?.signal, async (signal) => {
|
|
@@ -41,53 +42,53 @@ var AgentClient = class {
|
|
|
41
42
|
};
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
|
-
async openSession(
|
|
45
|
+
async openSession(name, mode, options) {
|
|
45
46
|
assertRoleExists(this.config.roles, options?.role);
|
|
46
|
-
const
|
|
47
|
-
const open = this.openSessions.get(
|
|
47
|
+
const sessionName = normalizeSessionName(name);
|
|
48
|
+
const open = this.openSessions.get(sessionName);
|
|
48
49
|
if (open) {
|
|
49
|
-
if (mode === "create") throw new Error(`[flue] Session "${
|
|
50
|
-
if (options?.role !== void 0 && options.role !== open.role) throw new Error(`[flue] Session "${
|
|
50
|
+
if (mode === "create") throw new Error(`[flue] Session "${sessionName}" already exists in harness "${this.name}".`);
|
|
51
|
+
if (options?.role !== void 0 && options.role !== open.role) throw new Error(`[flue] Session "${sessionName}" is already open with role ${JSON.stringify(open.role ?? null)}; cannot reopen with role ${JSON.stringify(options.role)}.`);
|
|
51
52
|
return open;
|
|
52
53
|
}
|
|
53
|
-
const storageKey = createSessionStorageKey(this.
|
|
54
|
+
const storageKey = createSessionStorageKey(this.instanceId, this.name, sessionName);
|
|
54
55
|
const existingData = await this.store.load(storageKey);
|
|
55
|
-
if (mode === "get" && !existingData) throw new Error(`[flue] Session "${
|
|
56
|
-
if (mode === "create" && existingData) throw new Error(`[flue] Session "${
|
|
56
|
+
if (mode === "get" && !existingData) throw new Error(`[flue] Session "${sessionName}" does not exist in harness "${this.name}".`);
|
|
57
|
+
if (mode === "create" && existingData) throw new Error(`[flue] Session "${sessionName}" already exists in harness "${this.name}".`);
|
|
57
58
|
let data = existingData;
|
|
58
59
|
if (!data && mode !== "get") {
|
|
59
60
|
data = createEmptySessionData();
|
|
60
61
|
await this.store.save(storageKey, data);
|
|
61
62
|
}
|
|
62
63
|
const session = new Session({
|
|
63
|
-
|
|
64
|
+
name: sessionName,
|
|
64
65
|
storageKey,
|
|
65
66
|
config: this.config,
|
|
66
67
|
env: this.env,
|
|
67
68
|
store: this.store,
|
|
68
69
|
existingData: data,
|
|
69
|
-
onAgentEvent: this.eventCallback,
|
|
70
|
+
onAgentEvent: this.decorateEventCallback(this.eventCallback),
|
|
70
71
|
agentTools: this.agentTools,
|
|
71
72
|
sessionRole: options?.role,
|
|
72
73
|
taskDepth: 0,
|
|
73
74
|
createTaskSession: (taskOptions) => this.createTaskSession(taskOptions),
|
|
74
|
-
onDelete: () => this.openSessions.delete(
|
|
75
|
+
onDelete: () => this.openSessions.delete(sessionName)
|
|
75
76
|
});
|
|
76
|
-
this.openSessions.set(
|
|
77
|
+
this.openSessions.set(sessionName, session);
|
|
77
78
|
return session;
|
|
78
79
|
}
|
|
79
|
-
async deleteSession(
|
|
80
|
-
const
|
|
81
|
-
const open = this.openSessions.get(
|
|
80
|
+
async deleteSession(name) {
|
|
81
|
+
const sessionName = normalizeSessionName(name);
|
|
82
|
+
const open = this.openSessions.get(sessionName);
|
|
82
83
|
if (open) {
|
|
83
84
|
await open.delete();
|
|
84
85
|
return;
|
|
85
86
|
}
|
|
86
|
-
await deleteSessionTree(this.store, createSessionStorageKey(this.
|
|
87
|
+
await deleteSessionTree(this.store, createSessionStorageKey(this.instanceId, this.name, sessionName));
|
|
87
88
|
}
|
|
88
89
|
async createTaskSession(options) {
|
|
89
90
|
assertRoleExists(this.config.roles, options.role);
|
|
90
|
-
const
|
|
91
|
+
const sessionName = `task:${options.parentSession}:${options.taskId}`;
|
|
91
92
|
const taskEnv = options.cwd ? createCwdSessionEnv(options.parentEnv, options.parentEnv.resolvePath(options.cwd)) : options.parentEnv;
|
|
92
93
|
const localContext = await discoverSessionContext(taskEnv);
|
|
93
94
|
const taskConfig = {
|
|
@@ -95,10 +96,10 @@ var AgentClient = class {
|
|
|
95
96
|
systemPrompt: localContext.systemPrompt,
|
|
96
97
|
skills: localContext.skills
|
|
97
98
|
};
|
|
98
|
-
const storageKey = createSessionStorageKey(this.
|
|
99
|
+
const storageKey = createSessionStorageKey(this.instanceId, this.name, sessionName);
|
|
99
100
|
const data = createEmptySessionData();
|
|
100
101
|
data.metadata = {
|
|
101
|
-
|
|
102
|
+
parentSession: options.parentSession,
|
|
102
103
|
taskId: options.taskId,
|
|
103
104
|
cwd: taskEnv.cwd,
|
|
104
105
|
role: options.role,
|
|
@@ -108,12 +109,13 @@ var AgentClient = class {
|
|
|
108
109
|
const eventCallback = this.eventCallback ? (event) => {
|
|
109
110
|
this.eventCallback?.({
|
|
110
111
|
...event,
|
|
111
|
-
|
|
112
|
+
harness: event.harness ?? this.name,
|
|
113
|
+
parentSession: event.parentSession ?? options.parentSession,
|
|
112
114
|
taskId: event.taskId ?? options.taskId
|
|
113
115
|
});
|
|
114
116
|
} : void 0;
|
|
115
117
|
return new Session({
|
|
116
|
-
|
|
118
|
+
name: sessionName,
|
|
117
119
|
storageKey,
|
|
118
120
|
config: taskConfig,
|
|
119
121
|
env: taskEnv,
|
|
@@ -126,17 +128,29 @@ var AgentClient = class {
|
|
|
126
128
|
createTaskSession: (childOptions) => this.createTaskSession(childOptions)
|
|
127
129
|
});
|
|
128
130
|
}
|
|
131
|
+
decorateEventCallback(callback) {
|
|
132
|
+
return callback ? (event) => {
|
|
133
|
+
callback({
|
|
134
|
+
...event,
|
|
135
|
+
harness: event.harness ?? this.name
|
|
136
|
+
});
|
|
137
|
+
} : void 0;
|
|
138
|
+
}
|
|
129
139
|
};
|
|
130
|
-
function
|
|
131
|
-
return
|
|
140
|
+
function normalizeSessionName(name) {
|
|
141
|
+
return name ?? DEFAULT_SESSION_NAME;
|
|
132
142
|
}
|
|
133
|
-
function createSessionStorageKey(
|
|
134
|
-
return `agent-session:${JSON.stringify([
|
|
143
|
+
function createSessionStorageKey(instanceId, harness, sessionName) {
|
|
144
|
+
return `agent-session:${JSON.stringify([
|
|
145
|
+
instanceId,
|
|
146
|
+
harness,
|
|
147
|
+
sessionName
|
|
148
|
+
])}`;
|
|
135
149
|
}
|
|
136
150
|
function createEmptySessionData() {
|
|
137
151
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
138
152
|
return {
|
|
139
|
-
version:
|
|
153
|
+
version: 3,
|
|
140
154
|
entries: [],
|
|
141
155
|
leafId: null,
|
|
142
156
|
metadata: {},
|
|
@@ -269,4 +283,4 @@ function formatMcpResult(result) {
|
|
|
269
283
|
}
|
|
270
284
|
|
|
271
285
|
//#endregion
|
|
272
|
-
export {
|
|
286
|
+
export { Harness as n, connectMcpServer as t };
|
package/dist/node/index.d.mts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { registerApiProvider } from "@mariozechner/pi-ai";
|
|
2
|
+
import { ulid } from "ulidx";
|
|
2
3
|
|
|
4
|
+
//#region src/runtime/ids.ts
|
|
5
|
+
function generateRunId() {
|
|
6
|
+
return `run_${ulid()}`;
|
|
7
|
+
}
|
|
8
|
+
function generateOperationId() {
|
|
9
|
+
return `op_${ulid()}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
3
13
|
//#region src/cloudflare-model.ts
|
|
4
14
|
/** Pi-ai `Api` slug for the binding-backed Workers AI provider. */
|
|
5
15
|
const CLOUDFLARE_AI_BINDING_API = "cloudflare-ai-binding";
|
|
@@ -155,4 +165,4 @@ function effectiveProviderSlug(name, def) {
|
|
|
155
165
|
}
|
|
156
166
|
|
|
157
167
|
//#endregion
|
|
158
|
-
export { registerApiProvider$1 as a, CLOUDFLARE_AI_BINDING_API as c, getRegisteredApiKey as i, getModelBinding as n, registerProvider as o, getProviderConfiguration as r, resolveRegisteredModel as s, configureProvider as t };
|
|
168
|
+
export { registerApiProvider$1 as a, CLOUDFLARE_AI_BINDING_API as c, getRegisteredApiKey as i, generateOperationId as l, getModelBinding as n, registerProvider as o, getProviderConfiguration as r, resolveRegisteredModel as s, configureProvider as t, generateRunId as u };
|
package/dist/sandbox.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as SandboxFactory, M as ShellResult, O as SessionEnv,
|
|
1
|
+
import { E as SandboxFactory, M as ShellResult, O as SessionEnv, i as BashFactory, m as FlueFs, u as FileStat } from "./types-Cdcq_ET2.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/sandbox.d.ts
|
|
4
4
|
/** Adapt a SessionEnv to the public FlueFs surface. */
|
package/dist/sandbox.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./result-K1IRhWKM.mjs";
|
|
2
|
-
import "./providers-
|
|
2
|
+
import "./providers-BjEEoKLy.mjs";
|
|
3
3
|
import { t as abortErrorFor } from "./abort-Bg3qsAkU.mjs";
|
|
4
|
-
import { i as normalizePath } from "./session-
|
|
4
|
+
import { i as normalizePath } from "./session-CRFfAJDq.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/sandbox.ts
|
|
7
7
|
/** Adapt a SessionEnv to the public FlueFs surface. */
|