@flue/sdk 0.4.1 → 0.5.1
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-DM6yv_Qc.mjs → mcp-0-egKS1N.mjs} +59 -38
- package/dist/{mcp-C3UBXVkR.d.mts → mcp-BfcWmA-A.d.mts} +1 -1
- 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-BQULcLE9.mjs} +203 -80
- 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-BQULcLE9.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,55 @@ 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);
|
|
55
|
+
const affinityKey = createSessionAffinityKey(this.instanceId, this.name, sessionName);
|
|
54
56
|
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 "${
|
|
57
|
+
if (mode === "get" && !existingData) throw new Error(`[flue] Session "${sessionName}" does not exist in harness "${this.name}".`);
|
|
58
|
+
if (mode === "create" && existingData) throw new Error(`[flue] Session "${sessionName}" already exists in harness "${this.name}".`);
|
|
57
59
|
let data = existingData;
|
|
58
60
|
if (!data && mode !== "get") {
|
|
59
61
|
data = createEmptySessionData();
|
|
60
62
|
await this.store.save(storageKey, data);
|
|
61
63
|
}
|
|
62
64
|
const session = new Session({
|
|
63
|
-
|
|
65
|
+
name: sessionName,
|
|
64
66
|
storageKey,
|
|
67
|
+
affinityKey,
|
|
65
68
|
config: this.config,
|
|
66
69
|
env: this.env,
|
|
67
70
|
store: this.store,
|
|
68
71
|
existingData: data,
|
|
69
|
-
onAgentEvent: this.eventCallback,
|
|
72
|
+
onAgentEvent: this.decorateEventCallback(this.eventCallback),
|
|
70
73
|
agentTools: this.agentTools,
|
|
71
74
|
sessionRole: options?.role,
|
|
72
75
|
taskDepth: 0,
|
|
73
76
|
createTaskSession: (taskOptions) => this.createTaskSession(taskOptions),
|
|
74
|
-
onDelete: () => this.openSessions.delete(
|
|
77
|
+
onDelete: () => this.openSessions.delete(sessionName)
|
|
75
78
|
});
|
|
76
|
-
this.openSessions.set(
|
|
79
|
+
this.openSessions.set(sessionName, session);
|
|
77
80
|
return session;
|
|
78
81
|
}
|
|
79
|
-
async deleteSession(
|
|
80
|
-
const
|
|
81
|
-
const open = this.openSessions.get(
|
|
82
|
+
async deleteSession(name) {
|
|
83
|
+
const sessionName = normalizeSessionName(name);
|
|
84
|
+
const open = this.openSessions.get(sessionName);
|
|
82
85
|
if (open) {
|
|
83
86
|
await open.delete();
|
|
84
87
|
return;
|
|
85
88
|
}
|
|
86
|
-
await deleteSessionTree(this.store, createSessionStorageKey(this.
|
|
89
|
+
await deleteSessionTree(this.store, createSessionStorageKey(this.instanceId, this.name, sessionName));
|
|
87
90
|
}
|
|
88
91
|
async createTaskSession(options) {
|
|
89
92
|
assertRoleExists(this.config.roles, options.role);
|
|
90
|
-
const
|
|
93
|
+
const sessionName = `task:${options.parentSession}:${options.taskId}`;
|
|
91
94
|
const taskEnv = options.cwd ? createCwdSessionEnv(options.parentEnv, options.parentEnv.resolvePath(options.cwd)) : options.parentEnv;
|
|
92
95
|
const localContext = await discoverSessionContext(taskEnv);
|
|
93
96
|
const taskConfig = {
|
|
@@ -95,10 +98,11 @@ var AgentClient = class {
|
|
|
95
98
|
systemPrompt: localContext.systemPrompt,
|
|
96
99
|
skills: localContext.skills
|
|
97
100
|
};
|
|
98
|
-
const storageKey = createSessionStorageKey(this.
|
|
101
|
+
const storageKey = createSessionStorageKey(this.instanceId, this.name, sessionName);
|
|
102
|
+
const affinityKey = createSessionAffinityKey(this.instanceId, this.name, sessionName);
|
|
99
103
|
const data = createEmptySessionData();
|
|
100
104
|
data.metadata = {
|
|
101
|
-
|
|
105
|
+
parentSession: options.parentSession,
|
|
102
106
|
taskId: options.taskId,
|
|
103
107
|
cwd: taskEnv.cwd,
|
|
104
108
|
role: options.role,
|
|
@@ -108,13 +112,15 @@ var AgentClient = class {
|
|
|
108
112
|
const eventCallback = this.eventCallback ? (event) => {
|
|
109
113
|
this.eventCallback?.({
|
|
110
114
|
...event,
|
|
111
|
-
|
|
115
|
+
harness: event.harness ?? this.name,
|
|
116
|
+
parentSession: event.parentSession ?? options.parentSession,
|
|
112
117
|
taskId: event.taskId ?? options.taskId
|
|
113
118
|
});
|
|
114
119
|
} : void 0;
|
|
115
120
|
return new Session({
|
|
116
|
-
|
|
121
|
+
name: sessionName,
|
|
117
122
|
storageKey,
|
|
123
|
+
affinityKey,
|
|
118
124
|
config: taskConfig,
|
|
119
125
|
env: taskEnv,
|
|
120
126
|
store: this.store,
|
|
@@ -126,17 +132,32 @@ var AgentClient = class {
|
|
|
126
132
|
createTaskSession: (childOptions) => this.createTaskSession(childOptions)
|
|
127
133
|
});
|
|
128
134
|
}
|
|
135
|
+
decorateEventCallback(callback) {
|
|
136
|
+
return callback ? (event) => {
|
|
137
|
+
callback({
|
|
138
|
+
...event,
|
|
139
|
+
harness: event.harness ?? this.name
|
|
140
|
+
});
|
|
141
|
+
} : void 0;
|
|
142
|
+
}
|
|
129
143
|
};
|
|
130
|
-
function
|
|
131
|
-
return
|
|
144
|
+
function normalizeSessionName(name) {
|
|
145
|
+
return name ?? DEFAULT_SESSION_NAME;
|
|
146
|
+
}
|
|
147
|
+
function createSessionStorageKey(instanceId, harness, sessionName) {
|
|
148
|
+
return `agent-session:${JSON.stringify([
|
|
149
|
+
instanceId,
|
|
150
|
+
harness,
|
|
151
|
+
sessionName
|
|
152
|
+
])}`;
|
|
132
153
|
}
|
|
133
|
-
function
|
|
134
|
-
return
|
|
154
|
+
function createSessionAffinityKey(instanceId, harness, sessionName) {
|
|
155
|
+
return `${instanceId}::${harness}::${sessionName}`;
|
|
135
156
|
}
|
|
136
157
|
function createEmptySessionData() {
|
|
137
158
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
138
159
|
return {
|
|
139
|
-
version:
|
|
160
|
+
version: 3,
|
|
140
161
|
entries: [],
|
|
141
162
|
leafId: null,
|
|
142
163
|
metadata: {},
|
|
@@ -269,4 +290,4 @@ function formatMcpResult(result) {
|
|
|
269
290
|
}
|
|
270
291
|
|
|
271
292
|
//#endregion
|
|
272
|
-
export {
|
|
293
|
+
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-BQULcLE9.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/sandbox.ts
|
|
7
7
|
/** Adapt a SessionEnv to the public FlueFs surface. */
|