@deepagents/experimental 6.0.0 → 6.1.2
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 +8 -0
- package/dist/index.js +577 -43
- package/dist/index.js.map +4 -4
- package/dist/zukhruf/agent.d.ts +5 -1
- package/dist/zukhruf/agent.d.ts.map +1 -1
- package/dist/zukhruf/control-plane/agent-declaration-registry.d.ts +1 -0
- package/dist/zukhruf/control-plane/agent-declaration-registry.d.ts.map +1 -1
- package/dist/zukhruf/index.d.ts +1 -0
- package/dist/zukhruf/index.d.ts.map +1 -1
- package/dist/zukhruf/index.js +577 -43
- package/dist/zukhruf/index.js.map +4 -4
- package/dist/zukhruf/protocol/parse.d.ts +3 -0
- package/dist/zukhruf/protocol/parse.d.ts.map +1 -0
- package/dist/zukhruf/protocol/session.d.ts +23 -0
- package/dist/zukhruf/protocol/session.d.ts.map +1 -0
- package/dist/zukhruf/protocol/validator.d.ts +64 -0
- package/dist/zukhruf/protocol/validator.d.ts.map +1 -0
- package/dist/zukhruf/runtime/agent-runtime.d.ts +16 -1
- package/dist/zukhruf/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/zukhruf/runtime/agent-skills.d.ts +9 -0
- package/dist/zukhruf/runtime/agent-skills.d.ts.map +1 -0
- package/dist/zukhruf/runtime/agent-turn-executor.d.ts.map +1 -1
- package/dist/zukhruf/sandbox/define.d.ts +4 -3
- package/dist/zukhruf/sandbox/define.d.ts.map +1 -1
- package/package.json +6 -4
package/dist/index.js
CHANGED
|
@@ -330,13 +330,22 @@ __export(zukhruf_exports, {
|
|
|
330
330
|
PgBossTurnQueue: () => PgBossTurnQueue,
|
|
331
331
|
SqliteMailboxStore: () => SqliteMailboxStore,
|
|
332
332
|
TurnQueue: () => TurnQueue,
|
|
333
|
+
ZUKHRUF_CREATE_SESSION_ROUTE_PATH: () => ZUKHRUF_CREATE_SESSION_ROUTE_PATH,
|
|
334
|
+
ZUKHRUF_HEALTH_ROUTE_PATH: () => ZUKHRUF_HEALTH_ROUTE_PATH,
|
|
335
|
+
ZUKHRUF_INFO_ROUTE_PATH: () => ZUKHRUF_INFO_ROUTE_PATH,
|
|
336
|
+
ZUKHRUF_ROUTE_PREFIX: () => ZUKHRUF_ROUTE_PREFIX,
|
|
337
|
+
ZUKHRUF_SESSION_CANCEL_ROUTE_PATH: () => ZUKHRUF_SESSION_CANCEL_ROUTE_PATH,
|
|
338
|
+
ZUKHRUF_SESSION_ID_HEADER: () => ZUKHRUF_SESSION_ID_HEADER,
|
|
339
|
+
ZUKHRUF_SESSION_ROUTE_PATH: () => ZUKHRUF_SESSION_ROUTE_PATH,
|
|
340
|
+
ZUKHRUF_SESSION_STREAM_ROUTE_PATH: () => ZUKHRUF_SESSION_STREAM_ROUTE_PATH,
|
|
333
341
|
assertCommunication: () => assertCommunication,
|
|
334
342
|
createInterAgentCommunication: () => createInterAgentCommunication,
|
|
335
343
|
defineAgent: () => defineAgent,
|
|
336
344
|
defineInstructions: () => defineInstructions,
|
|
337
345
|
defineSandbox: () => defineSandbox,
|
|
338
346
|
defineTool: () => defineTool,
|
|
339
|
-
renderTurn: () => renderTurn
|
|
347
|
+
renderTurn: () => renderTurn,
|
|
348
|
+
zukhruf: () => zukhruf
|
|
340
349
|
});
|
|
341
350
|
|
|
342
351
|
// packages/experimental/src/zukhruf/agent.ts
|
|
@@ -362,17 +371,17 @@ var AgentPath = class _AgentPath {
|
|
|
362
371
|
return new _AgentPath("/root");
|
|
363
372
|
}
|
|
364
373
|
static parse(value) {
|
|
365
|
-
const
|
|
366
|
-
if (
|
|
374
|
+
const path2 = value.trim();
|
|
375
|
+
if (path2 !== "/root" && !path2.startsWith("/root/")) {
|
|
367
376
|
throw new Error(`agent path "${value}" must start at /root`);
|
|
368
377
|
}
|
|
369
|
-
const segments =
|
|
378
|
+
const segments = path2.slice(1).split("/");
|
|
370
379
|
if (segments.some(
|
|
371
380
|
(segment) => segment.length === 0 || segment !== segment.trim() || segment === "." || segment === ".."
|
|
372
381
|
)) {
|
|
373
382
|
throw new Error(`agent path "${value}" contains an invalid segment`);
|
|
374
383
|
}
|
|
375
|
-
return new _AgentPath(
|
|
384
|
+
return new _AgentPath(path2);
|
|
376
385
|
}
|
|
377
386
|
/** Relative targets name descendants; absolute targets keep their canonical path. */
|
|
378
387
|
resolve(target) {
|
|
@@ -436,21 +445,21 @@ var AgentThread = class _AgentThread {
|
|
|
436
445
|
}
|
|
437
446
|
static fromMetadata(conversation, metadata) {
|
|
438
447
|
const treeId = metadata?.zukhrufTreeId;
|
|
439
|
-
const
|
|
440
|
-
if (typeof treeId !== "string" || !_AgentThread.#isRecord(
|
|
448
|
+
const zukhruf2 = metadata?.zukhruf;
|
|
449
|
+
if (typeof treeId !== "string" || !_AgentThread.#isRecord(zukhruf2)) {
|
|
441
450
|
return void 0;
|
|
442
451
|
}
|
|
443
|
-
const { path, parentChatId, declarationName, lastTurnId } =
|
|
444
|
-
if (typeof
|
|
452
|
+
const { path: path2, parentChatId, declarationName, lastTurnId } = zukhruf2;
|
|
453
|
+
if (typeof path2 !== "string" || parentChatId !== null && typeof parentChatId !== "string" || typeof declarationName !== "string" || lastTurnId !== void 0 && typeof lastTurnId !== "string") {
|
|
445
454
|
return void 0;
|
|
446
455
|
}
|
|
447
456
|
let parsedPath;
|
|
448
457
|
try {
|
|
449
|
-
parsedPath = AgentPath.parse(
|
|
458
|
+
parsedPath = AgentPath.parse(path2);
|
|
450
459
|
} catch {
|
|
451
460
|
return void 0;
|
|
452
461
|
}
|
|
453
|
-
if (parsedPath.toString() !==
|
|
462
|
+
if (parsedPath.toString() !== path2) return void 0;
|
|
454
463
|
try {
|
|
455
464
|
return new _AgentThread({
|
|
456
465
|
conversation,
|
|
@@ -575,6 +584,9 @@ var AgentDeclarationRegistry = class {
|
|
|
575
584
|
get(name) {
|
|
576
585
|
return this.#declarations.get(name);
|
|
577
586
|
}
|
|
587
|
+
values() {
|
|
588
|
+
return this.#declarations.values();
|
|
589
|
+
}
|
|
578
590
|
#register(declaration, visited) {
|
|
579
591
|
if (visited.has(declaration)) return;
|
|
580
592
|
visited.add(declaration);
|
|
@@ -671,20 +683,20 @@ var AgentDirectory = class _AgentDirectory {
|
|
|
671
683
|
);
|
|
672
684
|
}
|
|
673
685
|
async resolve(thread, target) {
|
|
674
|
-
const
|
|
686
|
+
const path2 = thread.path.resolve(target);
|
|
675
687
|
const match = await this.find(thread, target);
|
|
676
688
|
if (match) return match;
|
|
677
|
-
throw new Error(`agent path "${
|
|
689
|
+
throw new Error(`agent path "${path2}" does not exist in this tree`);
|
|
678
690
|
}
|
|
679
691
|
async find(thread, target) {
|
|
680
|
-
const
|
|
692
|
+
const path2 = thread.path.resolve(target);
|
|
681
693
|
return (await this.listTree(thread)).find(
|
|
682
|
-
(candidate) => candidate.path.equals(
|
|
694
|
+
(candidate) => candidate.path.equals(path2)
|
|
683
695
|
);
|
|
684
696
|
}
|
|
685
697
|
async createChild(options) {
|
|
686
|
-
const
|
|
687
|
-
const pathString =
|
|
698
|
+
const path2 = options.parent.path.resolve(options.taskName);
|
|
699
|
+
const pathString = path2.toString();
|
|
688
700
|
const conversation = {
|
|
689
701
|
chatId: _AgentDirectory.#childChatId(
|
|
690
702
|
options.parent.conversation.userId,
|
|
@@ -694,7 +706,7 @@ var AgentDirectory = class _AgentDirectory {
|
|
|
694
706
|
userId: options.parent.conversation.userId
|
|
695
707
|
};
|
|
696
708
|
const occupied = (await this.listTree(options.parent)).find(
|
|
697
|
-
(thread) => thread.path.equals(
|
|
709
|
+
(thread) => thread.path.equals(path2)
|
|
698
710
|
);
|
|
699
711
|
if (occupied && occupied.conversation.chatId !== conversation.chatId) {
|
|
700
712
|
throw new Error(`agent path "${pathString}" already exists`);
|
|
@@ -702,7 +714,7 @@ var AgentDirectory = class _AgentDirectory {
|
|
|
702
714
|
const child = new AgentThread({
|
|
703
715
|
conversation,
|
|
704
716
|
treeId: options.parent.treeId,
|
|
705
|
-
path,
|
|
717
|
+
path: path2,
|
|
706
718
|
parentChatId: options.parent.conversation.chatId,
|
|
707
719
|
declarationName: options.declarationName
|
|
708
720
|
});
|
|
@@ -720,9 +732,9 @@ var AgentDirectory = class _AgentDirectory {
|
|
|
720
732
|
}
|
|
721
733
|
return stored;
|
|
722
734
|
}
|
|
723
|
-
static #childChatId(userId, treeId,
|
|
735
|
+
static #childChatId(userId, treeId, path2) {
|
|
724
736
|
return uuidv5(
|
|
725
|
-
`urn:deepagents:zukhruf:agent:${JSON.stringify([userId, treeId,
|
|
737
|
+
`urn:deepagents:zukhruf:agent:${JSON.stringify([userId, treeId, path2])}`,
|
|
726
738
|
uuidv5.URL
|
|
727
739
|
);
|
|
728
740
|
}
|
|
@@ -859,14 +871,14 @@ var AgentHistoryForker = class {
|
|
|
859
871
|
let claimed;
|
|
860
872
|
await this.#store.updateChat(child.conversation.chatId, (chat2) => {
|
|
861
873
|
const metadata = chat2.metadata;
|
|
862
|
-
const
|
|
863
|
-
if (!isRecord(
|
|
874
|
+
const zukhruf2 = metadata?.zukhruf;
|
|
875
|
+
if (!isRecord(zukhruf2)) {
|
|
864
876
|
throw new Error(
|
|
865
877
|
`spawn_agent: child chat "${child.conversation.chatId}" is missing Zukhruf metadata`
|
|
866
878
|
);
|
|
867
879
|
}
|
|
868
|
-
if (
|
|
869
|
-
claimed = parseHistoryForkRecord(
|
|
880
|
+
if (zukhruf2.historyFork !== void 0) {
|
|
881
|
+
claimed = parseHistoryForkRecord(zukhruf2.historyFork);
|
|
870
882
|
if (claimed.parentChatId !== proposed.parentChatId || claimed.forkTurns !== proposed.forkTurns) {
|
|
871
883
|
throw new Error(
|
|
872
884
|
`spawn_agent: agent path "${child.path}" already exists with a different fork_turns setting`
|
|
@@ -878,7 +890,7 @@ var AgentHistoryForker = class {
|
|
|
878
890
|
return {
|
|
879
891
|
metadata: {
|
|
880
892
|
...metadata,
|
|
881
|
-
zukhruf: { ...
|
|
893
|
+
zukhruf: { ...zukhruf2, historyFork: proposed }
|
|
882
894
|
}
|
|
883
895
|
};
|
|
884
896
|
});
|
|
@@ -965,13 +977,13 @@ var AgentHistoryForker = class {
|
|
|
965
977
|
let sourceMessageIds;
|
|
966
978
|
await this.#store.updateChat(child.conversation.chatId, (chat2) => {
|
|
967
979
|
const metadata = chat2.metadata;
|
|
968
|
-
const
|
|
969
|
-
if (!isRecord(
|
|
980
|
+
const zukhruf2 = metadata?.zukhruf;
|
|
981
|
+
if (!isRecord(zukhruf2)) {
|
|
970
982
|
throw new Error(
|
|
971
983
|
`spawn_agent: child chat "${child.conversation.chatId}" is missing Zukhruf metadata`
|
|
972
984
|
);
|
|
973
985
|
}
|
|
974
|
-
const record = parseHistoryForkRecord(
|
|
986
|
+
const record = parseHistoryForkRecord(zukhruf2.historyFork);
|
|
975
987
|
if (record.sourceMessageIds !== void 0) {
|
|
976
988
|
sourceMessageIds = record.sourceMessageIds;
|
|
977
989
|
return void 0;
|
|
@@ -981,7 +993,7 @@ var AgentHistoryForker = class {
|
|
|
981
993
|
metadata: {
|
|
982
994
|
...metadata,
|
|
983
995
|
zukhruf: {
|
|
984
|
-
...
|
|
996
|
+
...zukhruf2,
|
|
985
997
|
historyFork: { ...record, sourceMessageIds: proposedIds }
|
|
986
998
|
}
|
|
987
999
|
}
|
|
@@ -1863,6 +1875,59 @@ function configureTool(collaborationTool, config) {
|
|
|
1863
1875
|
};
|
|
1864
1876
|
}
|
|
1865
1877
|
|
|
1878
|
+
// packages/experimental/src/zukhruf/runtime/agent-skills.ts
|
|
1879
|
+
import path from "node:path";
|
|
1880
|
+
import {
|
|
1881
|
+
parseFrontmatter,
|
|
1882
|
+
skills
|
|
1883
|
+
} from "@deepagents/context";
|
|
1884
|
+
var EMPTY_SKILLS = { available: [], fragments: [] };
|
|
1885
|
+
async function discoverAgentSkills(sandbox, signal) {
|
|
1886
|
+
if (sandbox.workingDirectory === void 0) return EMPTY_SKILLS;
|
|
1887
|
+
const skillsDirectory = path.posix.join(sandbox.workingDirectory, "skills");
|
|
1888
|
+
const quotedSkillsDirectory = shellQuote(skillsDirectory);
|
|
1889
|
+
const result = await sandbox.sandbox.executeCommand(
|
|
1890
|
+
`if [ -d ${quotedSkillsDirectory} ]; then find ${quotedSkillsDirectory} -mindepth 1 -maxdepth 1 -type d -print; fi`,
|
|
1891
|
+
{ signal }
|
|
1892
|
+
);
|
|
1893
|
+
if (result.exitCode !== 0) {
|
|
1894
|
+
throw new Error(
|
|
1895
|
+
`AgentRuntime: failed to discover sandbox skills: ${result.stderr.trim() || `exit ${result.exitCode}`}`
|
|
1896
|
+
);
|
|
1897
|
+
}
|
|
1898
|
+
const skillDirectories = result.stdout.split("\n").filter(Boolean).filter((directory) => !path.posix.basename(directory).startsWith(".")).toSorted();
|
|
1899
|
+
if (skillDirectories.length === 0) return EMPTY_SKILLS;
|
|
1900
|
+
const discovered = await Promise.all(
|
|
1901
|
+
skillDirectories.map((directory) => loadSkill(sandbox, directory))
|
|
1902
|
+
);
|
|
1903
|
+
return createAgentSkills(discovered);
|
|
1904
|
+
}
|
|
1905
|
+
function createAgentSkills(available) {
|
|
1906
|
+
if (available.length === 0) return EMPTY_SKILLS;
|
|
1907
|
+
const snapshot = [...available];
|
|
1908
|
+
return { available: snapshot, fragments: [skills(snapshot)] };
|
|
1909
|
+
}
|
|
1910
|
+
async function loadSkill(sandbox, directory) {
|
|
1911
|
+
const directoryName = path.posix.basename(directory);
|
|
1912
|
+
const skillMd = await sandbox.sandbox.readFile(
|
|
1913
|
+
path.posix.join(directory, "SKILL.md")
|
|
1914
|
+
);
|
|
1915
|
+
const { frontmatter } = parseFrontmatter(skillMd);
|
|
1916
|
+
if (frontmatter.name !== directoryName) {
|
|
1917
|
+
throw new Error(
|
|
1918
|
+
`AgentRuntime: skill "${frontmatter.name}" must use matching directory "${directoryName}"`
|
|
1919
|
+
);
|
|
1920
|
+
}
|
|
1921
|
+
return {
|
|
1922
|
+
name: frontmatter.name,
|
|
1923
|
+
description: frontmatter.description,
|
|
1924
|
+
path: path.posix.join("skills", directoryName, "SKILL.md")
|
|
1925
|
+
};
|
|
1926
|
+
}
|
|
1927
|
+
function shellQuote(value) {
|
|
1928
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1866
1931
|
// packages/experimental/src/zukhruf/runtime/agent-turn-executor.ts
|
|
1867
1932
|
var AgentTurnExecutor = class {
|
|
1868
1933
|
#store;
|
|
@@ -1917,10 +1982,7 @@ var AgentTurnExecutor = class {
|
|
|
1917
1982
|
if (await this.#projectSkippedTerminalTurn(turn)) return;
|
|
1918
1983
|
const { declaration, thread } = await this.#controlPlane.resolve(turn);
|
|
1919
1984
|
const usageHint = thread.path.isRoot ? this.#multiAgentV2.rootAgentUsageHintText : this.#multiAgentV2.subagentUsageHintText;
|
|
1920
|
-
const engine = this.#engineFor(turn)
|
|
1921
|
-
...declaration.instructions,
|
|
1922
|
-
...usageHint === void 0 ? [] : [role(usageHint)]
|
|
1923
|
-
);
|
|
1985
|
+
const engine = this.#engineFor(turn);
|
|
1924
1986
|
if (turn.kind === "ask" || turn.kind === "mailbox") {
|
|
1925
1987
|
const head = (await engine.getMessages()).at(-1);
|
|
1926
1988
|
if (this.#approvals.isPaused(head)) {
|
|
@@ -1944,6 +2006,12 @@ var AgentTurnExecutor = class {
|
|
|
1944
2006
|
chatId: turn.chatId,
|
|
1945
2007
|
userId: turn.userId
|
|
1946
2008
|
});
|
|
2009
|
+
const agentSkills = await this.#skillsFor(turn, sandbox, signal);
|
|
2010
|
+
engine.set(
|
|
2011
|
+
...declaration.instructions,
|
|
2012
|
+
...agentSkills.fragments,
|
|
2013
|
+
...usageHint === void 0 ? [] : [role(usageHint)]
|
|
2014
|
+
);
|
|
1947
2015
|
if (await this.#projectSkippedTerminalTurn(turn)) return;
|
|
1948
2016
|
if (!await this.#streams.claim(turn.streamId)) {
|
|
1949
2017
|
await this.#projectSkippedTerminalTurn(turn);
|
|
@@ -2056,6 +2124,29 @@ var AgentTurnExecutor = class {
|
|
|
2056
2124
|
(communication) => this.#mailboxInputMessage(communication)
|
|
2057
2125
|
);
|
|
2058
2126
|
}
|
|
2127
|
+
async #skillsFor(turn, sandbox, signal) {
|
|
2128
|
+
const chat2 = await this.#store.getChat(turn.chatId);
|
|
2129
|
+
const existing = readSkills(chat2?.metadata);
|
|
2130
|
+
if (existing !== void 0) return createAgentSkills(existing);
|
|
2131
|
+
if (sandbox.workingDirectory === void 0) return createAgentSkills([]);
|
|
2132
|
+
const discovered = await discoverAgentSkills(sandbox, signal);
|
|
2133
|
+
let available = discovered.available;
|
|
2134
|
+
await this.#store.updateChat(turn.chatId, ({ metadata }) => {
|
|
2135
|
+
const persisted = readSkills(metadata);
|
|
2136
|
+
if (persisted !== void 0) {
|
|
2137
|
+
available = persisted;
|
|
2138
|
+
return void 0;
|
|
2139
|
+
}
|
|
2140
|
+
const zukhruf2 = isRecord2(metadata?.zukhruf) ? metadata.zukhruf : {};
|
|
2141
|
+
return {
|
|
2142
|
+
metadata: {
|
|
2143
|
+
...metadata,
|
|
2144
|
+
zukhruf: { ...zukhruf2, skills: available }
|
|
2145
|
+
}
|
|
2146
|
+
};
|
|
2147
|
+
});
|
|
2148
|
+
return available === discovered.available ? discovered : createAgentSkills(available);
|
|
2149
|
+
}
|
|
2059
2150
|
#engineFor({ chatId, userId }) {
|
|
2060
2151
|
return new ContextEngine2({ store: this.#store, chatId, userId });
|
|
2061
2152
|
}
|
|
@@ -2084,6 +2175,22 @@ Payload:
|
|
|
2084
2175
|
${communication.content}`;
|
|
2085
2176
|
}
|
|
2086
2177
|
};
|
|
2178
|
+
function readSkills(metadata) {
|
|
2179
|
+
const zukhruf2 = metadata?.zukhruf;
|
|
2180
|
+
if (!isRecord2(zukhruf2) || !Object.hasOwn(zukhruf2, "skills")) {
|
|
2181
|
+
return void 0;
|
|
2182
|
+
}
|
|
2183
|
+
if (!Array.isArray(zukhruf2.skills) || !zukhruf2.skills.every(isSkill)) {
|
|
2184
|
+
throw new Error("AgentRuntime: stored skill catalog is invalid");
|
|
2185
|
+
}
|
|
2186
|
+
return zukhruf2.skills;
|
|
2187
|
+
}
|
|
2188
|
+
function isSkill(value) {
|
|
2189
|
+
return isRecord2(value) && typeof value.name === "string" && typeof value.description === "string" && typeof value.path === "string";
|
|
2190
|
+
}
|
|
2191
|
+
function isRecord2(value) {
|
|
2192
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2193
|
+
}
|
|
2087
2194
|
|
|
2088
2195
|
// packages/experimental/src/zukhruf/runtime/approval-controller.ts
|
|
2089
2196
|
import {
|
|
@@ -2329,7 +2436,8 @@ var AgentObservation = class {
|
|
|
2329
2436
|
#conversation;
|
|
2330
2437
|
#store;
|
|
2331
2438
|
#streams;
|
|
2332
|
-
|
|
2439
|
+
#queue;
|
|
2440
|
+
constructor(conversation, store, streams, queue) {
|
|
2333
2441
|
this.engine = new ContextEngine4({
|
|
2334
2442
|
store,
|
|
2335
2443
|
chatId: conversation.chatId,
|
|
@@ -2338,6 +2446,7 @@ var AgentObservation = class {
|
|
|
2338
2446
|
this.#conversation = conversation;
|
|
2339
2447
|
this.#store = store;
|
|
2340
2448
|
this.#streams = streams;
|
|
2449
|
+
this.#queue = queue;
|
|
2341
2450
|
}
|
|
2342
2451
|
async resume() {
|
|
2343
2452
|
const id = await this.#headStreamId();
|
|
@@ -2357,16 +2466,27 @@ var AgentObservation = class {
|
|
|
2357
2466
|
if (!id) return;
|
|
2358
2467
|
AgentTurnId.assertOwner(this.#conversation, id);
|
|
2359
2468
|
const status = await this.#streams.store.getStreamStatus(id);
|
|
2360
|
-
if (status === "queued" || status === "running") {
|
|
2469
|
+
if (status === "queued" || status === "running" || status === "cancelled") {
|
|
2361
2470
|
await this.#streams.cancel(id);
|
|
2471
|
+
await this.#queue.cancel(id);
|
|
2362
2472
|
}
|
|
2363
2473
|
}
|
|
2364
2474
|
async #headStreamId() {
|
|
2475
|
+
const scheduled = await this.#queue.getCurrentTurn(this.#conversation);
|
|
2476
|
+
if (scheduled) return scheduled.streamId;
|
|
2477
|
+
const chat2 = await this.#store.getChat(this.#conversation.chatId);
|
|
2478
|
+
if (!chat2) return void 0;
|
|
2479
|
+
if (chat2.userId !== this.#conversation.userId) {
|
|
2480
|
+
throw new Error(
|
|
2481
|
+
`chat "${this.#conversation.chatId}" belongs to user "${chat2.userId}", not "${this.#conversation.userId}"`
|
|
2482
|
+
);
|
|
2483
|
+
}
|
|
2365
2484
|
const head = await this.engine.headMessage();
|
|
2366
2485
|
return head?.name === "assistant" ? head.id : void 0;
|
|
2367
2486
|
}
|
|
2368
2487
|
};
|
|
2369
2488
|
var AgentRuntime = class {
|
|
2489
|
+
info;
|
|
2370
2490
|
#store;
|
|
2371
2491
|
#queue;
|
|
2372
2492
|
#streams;
|
|
@@ -2415,6 +2535,18 @@ var AgentRuntime = class {
|
|
|
2415
2535
|
this.#directory = directory;
|
|
2416
2536
|
this.#controlPlane = controlPlane;
|
|
2417
2537
|
this.#approvals = approvals;
|
|
2538
|
+
this.info = {
|
|
2539
|
+
root: declarations.root.name,
|
|
2540
|
+
agents: Array.from(declarations.values(), (declaration) => ({
|
|
2541
|
+
name: declaration.name,
|
|
2542
|
+
model: {
|
|
2543
|
+
provider: declaration.model.provider,
|
|
2544
|
+
modelId: declaration.model.modelId
|
|
2545
|
+
},
|
|
2546
|
+
tools: Object.keys(declaration.tools ?? {}).sort(),
|
|
2547
|
+
subagents: (declaration.subagents ?? []).map(({ name }) => name)
|
|
2548
|
+
}))
|
|
2549
|
+
};
|
|
2418
2550
|
this.#executor = new AgentTurnExecutor({
|
|
2419
2551
|
store: options.store,
|
|
2420
2552
|
streams,
|
|
@@ -2424,6 +2556,14 @@ var AgentRuntime = class {
|
|
|
2424
2556
|
multiAgentV2
|
|
2425
2557
|
});
|
|
2426
2558
|
}
|
|
2559
|
+
async createSession(conversation) {
|
|
2560
|
+
await this.#controlPlane.resolve(conversation);
|
|
2561
|
+
}
|
|
2562
|
+
async sessionExists(conversation) {
|
|
2563
|
+
const chat2 = await this.#store.getChat(conversation.chatId);
|
|
2564
|
+
if (!chat2 || chat2.userId !== conversation.userId) return false;
|
|
2565
|
+
return (await this.#directory.load(conversation))?.path.isRoot ?? false;
|
|
2566
|
+
}
|
|
2427
2567
|
async enqueue(conversation, turn) {
|
|
2428
2568
|
const streamId = await this.#controlPlane.enqueue(conversation, turn);
|
|
2429
2569
|
return { id: streamId, stream: this.#streams.watch(streamId) };
|
|
@@ -2439,7 +2579,12 @@ var AgentRuntime = class {
|
|
|
2439
2579
|
return this.#approvals.deny(conversation, input);
|
|
2440
2580
|
}
|
|
2441
2581
|
observe(conversation) {
|
|
2442
|
-
return new AgentObservation(
|
|
2582
|
+
return new AgentObservation(
|
|
2583
|
+
conversation,
|
|
2584
|
+
this.#store,
|
|
2585
|
+
this.#streams,
|
|
2586
|
+
this.#queue
|
|
2587
|
+
);
|
|
2443
2588
|
}
|
|
2444
2589
|
work(options) {
|
|
2445
2590
|
return this.#queue.consume(this.#executor.execute.bind(this.#executor), {
|
|
@@ -2558,9 +2703,9 @@ var BUSY_TIMEOUT_MS = 5e3;
|
|
|
2558
2703
|
var SqliteMailboxStore = class extends MailboxStore {
|
|
2559
2704
|
#database;
|
|
2560
2705
|
#closed = false;
|
|
2561
|
-
constructor(
|
|
2706
|
+
constructor(path2) {
|
|
2562
2707
|
super();
|
|
2563
|
-
this.#database = new DatabaseSync(
|
|
2708
|
+
this.#database = new DatabaseSync(path2, { timeout: BUSY_TIMEOUT_MS });
|
|
2564
2709
|
this.#database.exec(DDL);
|
|
2565
2710
|
}
|
|
2566
2711
|
async beginTurn(recipient, turnId) {
|
|
@@ -2710,6 +2855,386 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
2710
2855
|
}
|
|
2711
2856
|
};
|
|
2712
2857
|
|
|
2858
|
+
// packages/experimental/src/zukhruf/protocol/session.ts
|
|
2859
|
+
import { createUIMessageStreamResponse } from "ai";
|
|
2860
|
+
import { Hono } from "hono";
|
|
2861
|
+
import { bodyLimit } from "hono/body-limit";
|
|
2862
|
+
import { HTTPException as HTTPException3 } from "hono/http-exception";
|
|
2863
|
+
import { v5 as uuidv56, validate as validateUuid } from "uuid";
|
|
2864
|
+
import z9 from "zod";
|
|
2865
|
+
|
|
2866
|
+
// packages/experimental/src/zukhruf/protocol/validator.ts
|
|
2867
|
+
import { parse as parseContentType } from "fast-content-type-parse";
|
|
2868
|
+
import { createMiddleware } from "hono/factory";
|
|
2869
|
+
import { HTTPException as HTTPException2 } from "hono/http-exception";
|
|
2870
|
+
import z8 from "zod";
|
|
2871
|
+
|
|
2872
|
+
// packages/experimental/src/zukhruf/protocol/parse.ts
|
|
2873
|
+
import { HTTPException } from "hono/http-exception";
|
|
2874
|
+
import "zod";
|
|
2875
|
+
async function parse(schema, input) {
|
|
2876
|
+
const result = await schema.safeParseAsync(input);
|
|
2877
|
+
if (!result.success) {
|
|
2878
|
+
const errors = result.error.flatten((issue) => ({
|
|
2879
|
+
message: issue.message,
|
|
2880
|
+
code: issue.code,
|
|
2881
|
+
path: issue.path.join(".")
|
|
2882
|
+
})).fieldErrors;
|
|
2883
|
+
throw new HTTPException(400, {
|
|
2884
|
+
message: "Validation failed",
|
|
2885
|
+
cause: {
|
|
2886
|
+
code: "api/validation-failed",
|
|
2887
|
+
detail: "The input data is invalid",
|
|
2888
|
+
errors
|
|
2889
|
+
}
|
|
2890
|
+
});
|
|
2891
|
+
}
|
|
2892
|
+
return result.data;
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
// packages/experimental/src/zukhruf/protocol/validator.ts
|
|
2896
|
+
function validate(expectedContentTypeOrSelector, selector) {
|
|
2897
|
+
const expectedContentType = typeof expectedContentTypeOrSelector === "string" ? expectedContentTypeOrSelector : void 0;
|
|
2898
|
+
const _selector = typeof expectedContentTypeOrSelector === "function" ? expectedContentTypeOrSelector : selector;
|
|
2899
|
+
if (!_selector) {
|
|
2900
|
+
throw new Error("Selector function is required");
|
|
2901
|
+
}
|
|
2902
|
+
return createMiddleware(async (c, next) => {
|
|
2903
|
+
const ct = c.req.header("content-type");
|
|
2904
|
+
if (c.req.method === "GET" && ct) {
|
|
2905
|
+
throw new HTTPException2(415, {
|
|
2906
|
+
message: "Unsupported Media Type",
|
|
2907
|
+
cause: {
|
|
2908
|
+
code: "api/unsupported-media-type",
|
|
2909
|
+
detail: `GET requests cannot have a content type header`
|
|
2910
|
+
}
|
|
2911
|
+
});
|
|
2912
|
+
}
|
|
2913
|
+
if (expectedContentType) {
|
|
2914
|
+
void verifyContentType(ct, expectedContentType);
|
|
2915
|
+
}
|
|
2916
|
+
const contentType = ct ? parseContentType(ct) : null;
|
|
2917
|
+
let body = null;
|
|
2918
|
+
switch (contentType?.type) {
|
|
2919
|
+
case "application/json":
|
|
2920
|
+
body = await parseJson(c);
|
|
2921
|
+
break;
|
|
2922
|
+
case "application/x-www-form-urlencoded":
|
|
2923
|
+
case "multipart/form-data":
|
|
2924
|
+
body = await c.req.parseBody();
|
|
2925
|
+
break;
|
|
2926
|
+
default:
|
|
2927
|
+
body = {};
|
|
2928
|
+
}
|
|
2929
|
+
const payload = {
|
|
2930
|
+
body,
|
|
2931
|
+
query: parseQueryParams(c.req.query()),
|
|
2932
|
+
queries: parseQueriesParams(c.req.queries()),
|
|
2933
|
+
params: c.req.param(),
|
|
2934
|
+
headers: Object.fromEntries(
|
|
2935
|
+
Object.entries(c.req.header()).map(([k, v]) => [k, v ?? ""])
|
|
2936
|
+
)
|
|
2937
|
+
};
|
|
2938
|
+
const config = _selector(payload);
|
|
2939
|
+
const schema = z8.object(
|
|
2940
|
+
Object.entries(config).reduce(
|
|
2941
|
+
(acc, [key, value]) => {
|
|
2942
|
+
acc[key] = value.against;
|
|
2943
|
+
return acc;
|
|
2944
|
+
},
|
|
2945
|
+
{}
|
|
2946
|
+
)
|
|
2947
|
+
);
|
|
2948
|
+
const input = Object.entries(config).reduce(
|
|
2949
|
+
(acc, [key, value]) => {
|
|
2950
|
+
acc[key] = value.select;
|
|
2951
|
+
return acc;
|
|
2952
|
+
},
|
|
2953
|
+
{}
|
|
2954
|
+
);
|
|
2955
|
+
const parsed = await parse(schema, input);
|
|
2956
|
+
c.set("input", parsed);
|
|
2957
|
+
await next();
|
|
2958
|
+
});
|
|
2959
|
+
}
|
|
2960
|
+
function verifyContentType(actual, expected) {
|
|
2961
|
+
if (!actual) {
|
|
2962
|
+
throw new HTTPException2(415, {
|
|
2963
|
+
message: "Unsupported Media Type",
|
|
2964
|
+
cause: {
|
|
2965
|
+
code: "api/unsupported-media-type",
|
|
2966
|
+
detail: "Missing content type header"
|
|
2967
|
+
}
|
|
2968
|
+
});
|
|
2969
|
+
}
|
|
2970
|
+
const { type: incomingContentType } = parseContentType(actual);
|
|
2971
|
+
if (incomingContentType !== expected) {
|
|
2972
|
+
throw new HTTPException2(415, {
|
|
2973
|
+
message: "Unsupported Media Type",
|
|
2974
|
+
cause: {
|
|
2975
|
+
code: "api/unsupported-media-type",
|
|
2976
|
+
detail: `Expected content type: ${expected}, but got: ${incomingContentType}`
|
|
2977
|
+
}
|
|
2978
|
+
});
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
async function parseJson(context) {
|
|
2982
|
+
try {
|
|
2983
|
+
return await context.req.json();
|
|
2984
|
+
} catch (error) {
|
|
2985
|
+
throw new HTTPException2(400, {
|
|
2986
|
+
message: "The request body is not valid JSON",
|
|
2987
|
+
cause: {
|
|
2988
|
+
code: "api/invalid-json",
|
|
2989
|
+
detail: error instanceof Error ? error.message : String(error)
|
|
2990
|
+
}
|
|
2991
|
+
});
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
function parseQueryParams(queryParams) {
|
|
2995
|
+
return Object.fromEntries(
|
|
2996
|
+
Object.entries(queryParams).map(([key, value]) => [
|
|
2997
|
+
key,
|
|
2998
|
+
value === "null" ? null : value
|
|
2999
|
+
])
|
|
3000
|
+
);
|
|
3001
|
+
}
|
|
3002
|
+
function parseQueriesParams(queriesParams) {
|
|
3003
|
+
return Object.fromEntries(
|
|
3004
|
+
Object.entries(queriesParams).map(([key, values]) => [
|
|
3005
|
+
key,
|
|
3006
|
+
values.map((value) => value === "null" ? null : value)
|
|
3007
|
+
])
|
|
3008
|
+
);
|
|
3009
|
+
}
|
|
3010
|
+
|
|
3011
|
+
// packages/experimental/src/zukhruf/protocol/session.ts
|
|
3012
|
+
var ZUKHRUF_ROUTE_PREFIX = "/zukhruf/v1";
|
|
3013
|
+
var CREATE_SESSION_ROUTE_PATH = "/session";
|
|
3014
|
+
var SESSION_ROUTE_PATH = "/session/:sessionId";
|
|
3015
|
+
var SESSION_CANCEL_ROUTE_PATH = "/session/:sessionId/cancel";
|
|
3016
|
+
var SESSION_STREAM_ROUTE_PATH = "/session/:sessionId/stream";
|
|
3017
|
+
var INFO_ROUTE_PATH = "/info";
|
|
3018
|
+
var HEALTH_ROUTE_PATH = "/health";
|
|
3019
|
+
var ZUKHRUF_CREATE_SESSION_ROUTE_PATH = `${ZUKHRUF_ROUTE_PREFIX}${CREATE_SESSION_ROUTE_PATH}`;
|
|
3020
|
+
var ZUKHRUF_SESSION_ROUTE_PATH = `${ZUKHRUF_ROUTE_PREFIX}${SESSION_ROUTE_PATH}`;
|
|
3021
|
+
var ZUKHRUF_SESSION_CANCEL_ROUTE_PATH = `${ZUKHRUF_ROUTE_PREFIX}${SESSION_CANCEL_ROUTE_PATH}`;
|
|
3022
|
+
var ZUKHRUF_SESSION_STREAM_ROUTE_PATH = `${ZUKHRUF_ROUTE_PREFIX}${SESSION_STREAM_ROUTE_PATH}`;
|
|
3023
|
+
var ZUKHRUF_INFO_ROUTE_PATH = `${ZUKHRUF_ROUTE_PREFIX}${INFO_ROUTE_PATH}`;
|
|
3024
|
+
var ZUKHRUF_HEALTH_ROUTE_PATH = `${ZUKHRUF_ROUTE_PREFIX}${HEALTH_ROUTE_PATH}`;
|
|
3025
|
+
var ZUKHRUF_SESSION_ID_HEADER = "x-zukhruf-session-id";
|
|
3026
|
+
var MAX_BODY_BYTES = 10 * 1024;
|
|
3027
|
+
var MAX_IDEMPOTENCY_KEY_LENGTH = 200;
|
|
3028
|
+
var MAX_INPUT_LENGTH = 8e3;
|
|
3029
|
+
var SESSION_NAMESPACE = uuidv56("urn:deepagents:zukhruf:sessions", uuidv56.URL);
|
|
3030
|
+
var NO_STORE = { "cache-control": "no-store" };
|
|
3031
|
+
var sessionIdSchema = z9.string().refine(validateUuid);
|
|
3032
|
+
var turnBodySchema = z9.strictObject({
|
|
3033
|
+
input: z9.string().trim().min(1).max(MAX_INPUT_LENGTH)
|
|
3034
|
+
});
|
|
3035
|
+
var idempotencyKeySchema = z9.string().trim().min(1).max(MAX_IDEMPOTENCY_KEY_LENGTH);
|
|
3036
|
+
var limitTurnBody = bodyLimit({
|
|
3037
|
+
maxSize: MAX_BODY_BYTES,
|
|
3038
|
+
onError: () => {
|
|
3039
|
+
throw new HTTPException3(413, {
|
|
3040
|
+
message: "Request body is too large",
|
|
3041
|
+
cause: {
|
|
3042
|
+
code: "api/payload-too-large",
|
|
3043
|
+
detail: `Request body exceeds ${MAX_BODY_BYTES} bytes`
|
|
3044
|
+
}
|
|
3045
|
+
});
|
|
3046
|
+
}
|
|
3047
|
+
});
|
|
3048
|
+
function zukhruf(runtime) {
|
|
3049
|
+
const app = new Hono();
|
|
3050
|
+
app.onError((error, context) => {
|
|
3051
|
+
if (error instanceof HTTPException3) {
|
|
3052
|
+
return context.json(
|
|
3053
|
+
{ cause: error.cause, error: error.message },
|
|
3054
|
+
error.status,
|
|
3055
|
+
NO_STORE
|
|
3056
|
+
);
|
|
3057
|
+
}
|
|
3058
|
+
throw error;
|
|
3059
|
+
});
|
|
3060
|
+
app.on(
|
|
3061
|
+
["GET", "HEAD"],
|
|
3062
|
+
HEALTH_ROUTE_PATH,
|
|
3063
|
+
(context) => context.req.method === "HEAD" ? context.body(null, 200, NO_STORE) : context.json({ ok: true }, 200, NO_STORE)
|
|
3064
|
+
);
|
|
3065
|
+
app.all(
|
|
3066
|
+
HEALTH_ROUTE_PATH,
|
|
3067
|
+
(context) => methodNotAllowed(context, "GET, HEAD")
|
|
3068
|
+
);
|
|
3069
|
+
app.use("*", async (context, next) => {
|
|
3070
|
+
if (!context.get("userId")?.trim()) {
|
|
3071
|
+
throw new HTTPException3(401, {
|
|
3072
|
+
message: "Authentication required",
|
|
3073
|
+
cause: {
|
|
3074
|
+
code: "api/unauthenticated",
|
|
3075
|
+
detail: "Authentication required to access Zukhruf"
|
|
3076
|
+
}
|
|
3077
|
+
});
|
|
3078
|
+
}
|
|
3079
|
+
await next();
|
|
3080
|
+
});
|
|
3081
|
+
app.get(
|
|
3082
|
+
INFO_ROUTE_PATH,
|
|
3083
|
+
(context) => context.json(runtime.info, 200, NO_STORE)
|
|
3084
|
+
);
|
|
3085
|
+
app.all(INFO_ROUTE_PATH, (context) => methodNotAllowed(context, "GET"));
|
|
3086
|
+
app.post(
|
|
3087
|
+
CREATE_SESSION_ROUTE_PATH,
|
|
3088
|
+
limitTurnBody,
|
|
3089
|
+
validate("application/json", (payload) => ({
|
|
3090
|
+
body: {
|
|
3091
|
+
select: payload.body,
|
|
3092
|
+
against: turnBodySchema
|
|
3093
|
+
},
|
|
3094
|
+
idempotencyKey: {
|
|
3095
|
+
select: payload.headers["idempotency-key"],
|
|
3096
|
+
against: idempotencyKeySchema
|
|
3097
|
+
}
|
|
3098
|
+
})),
|
|
3099
|
+
async (context) => {
|
|
3100
|
+
const { body, idempotencyKey } = context.var.input;
|
|
3101
|
+
const userId = context.get("userId");
|
|
3102
|
+
const sessionId = uuidv56(
|
|
3103
|
+
JSON.stringify([userId, idempotencyKey]),
|
|
3104
|
+
SESSION_NAMESPACE
|
|
3105
|
+
);
|
|
3106
|
+
const conversation = { chatId: sessionId, userId };
|
|
3107
|
+
await runtime.createSession(conversation);
|
|
3108
|
+
await runtime.enqueue(conversation, {
|
|
3109
|
+
id: idempotencyKey,
|
|
3110
|
+
input: body.input.trim()
|
|
3111
|
+
});
|
|
3112
|
+
return accepted(context, sessionId);
|
|
3113
|
+
}
|
|
3114
|
+
);
|
|
3115
|
+
app.all(
|
|
3116
|
+
CREATE_SESSION_ROUTE_PATH,
|
|
3117
|
+
(context) => methodNotAllowed(context, "POST")
|
|
3118
|
+
);
|
|
3119
|
+
app.post(
|
|
3120
|
+
SESSION_ROUTE_PATH,
|
|
3121
|
+
limitTurnBody,
|
|
3122
|
+
validate("application/json", (payload) => ({
|
|
3123
|
+
body: {
|
|
3124
|
+
select: payload.body,
|
|
3125
|
+
against: turnBodySchema
|
|
3126
|
+
},
|
|
3127
|
+
idempotencyKey: {
|
|
3128
|
+
select: payload.headers["idempotency-key"],
|
|
3129
|
+
against: idempotencyKeySchema
|
|
3130
|
+
},
|
|
3131
|
+
sessionId: {
|
|
3132
|
+
select: payload.params.sessionId,
|
|
3133
|
+
against: sessionIdSchema
|
|
3134
|
+
}
|
|
3135
|
+
})),
|
|
3136
|
+
async (context) => {
|
|
3137
|
+
const { body, idempotencyKey, sessionId } = context.var.input;
|
|
3138
|
+
const conversation = {
|
|
3139
|
+
chatId: sessionId,
|
|
3140
|
+
userId: context.get("userId")
|
|
3141
|
+
};
|
|
3142
|
+
await requireSession(runtime, conversation);
|
|
3143
|
+
await runtime.enqueue(conversation, {
|
|
3144
|
+
id: idempotencyKey,
|
|
3145
|
+
input: body.input.trim()
|
|
3146
|
+
});
|
|
3147
|
+
return accepted(context, sessionId);
|
|
3148
|
+
}
|
|
3149
|
+
);
|
|
3150
|
+
app.all(SESSION_ROUTE_PATH, (context) => methodNotAllowed(context, "POST"));
|
|
3151
|
+
app.post(
|
|
3152
|
+
SESSION_CANCEL_ROUTE_PATH,
|
|
3153
|
+
validate((payload) => ({
|
|
3154
|
+
sessionId: {
|
|
3155
|
+
select: payload.params.sessionId,
|
|
3156
|
+
against: sessionIdSchema
|
|
3157
|
+
}
|
|
3158
|
+
})),
|
|
3159
|
+
async (context) => {
|
|
3160
|
+
const { sessionId } = context.var.input;
|
|
3161
|
+
const conversation = {
|
|
3162
|
+
chatId: sessionId,
|
|
3163
|
+
userId: context.get("userId")
|
|
3164
|
+
};
|
|
3165
|
+
await requireSession(runtime, conversation);
|
|
3166
|
+
await runtime.observe(conversation).cancel();
|
|
3167
|
+
return context.body(null, 204, NO_STORE);
|
|
3168
|
+
}
|
|
3169
|
+
);
|
|
3170
|
+
app.all(
|
|
3171
|
+
SESSION_CANCEL_ROUTE_PATH,
|
|
3172
|
+
(context) => methodNotAllowed(context, "POST")
|
|
3173
|
+
);
|
|
3174
|
+
app.get(
|
|
3175
|
+
SESSION_STREAM_ROUTE_PATH,
|
|
3176
|
+
validate((payload) => ({
|
|
3177
|
+
sessionId: {
|
|
3178
|
+
select: payload.params.sessionId,
|
|
3179
|
+
against: sessionIdSchema
|
|
3180
|
+
}
|
|
3181
|
+
})),
|
|
3182
|
+
async (context) => {
|
|
3183
|
+
const { sessionId } = context.var.input;
|
|
3184
|
+
const conversation = {
|
|
3185
|
+
chatId: sessionId,
|
|
3186
|
+
userId: context.get("userId")
|
|
3187
|
+
};
|
|
3188
|
+
await requireSession(runtime, conversation);
|
|
3189
|
+
const stream = await runtime.observe(conversation).resume();
|
|
3190
|
+
if (!stream) {
|
|
3191
|
+
throw new HTTPException3(404, {
|
|
3192
|
+
message: "Session stream not found",
|
|
3193
|
+
cause: {
|
|
3194
|
+
code: "zukhruf/session-stream-not-found",
|
|
3195
|
+
detail: `No durable stream exists for session ${sessionId}`
|
|
3196
|
+
}
|
|
3197
|
+
});
|
|
3198
|
+
}
|
|
3199
|
+
return createUIMessageStreamResponse({
|
|
3200
|
+
headers: NO_STORE,
|
|
3201
|
+
stream
|
|
3202
|
+
});
|
|
3203
|
+
}
|
|
3204
|
+
);
|
|
3205
|
+
app.all(
|
|
3206
|
+
SESSION_STREAM_ROUTE_PATH,
|
|
3207
|
+
(context) => methodNotAllowed(context, "GET")
|
|
3208
|
+
);
|
|
3209
|
+
return app;
|
|
3210
|
+
}
|
|
3211
|
+
function accepted(context, sessionId) {
|
|
3212
|
+
return context.json({ ok: true, sessionId }, 202, {
|
|
3213
|
+
...NO_STORE,
|
|
3214
|
+
[ZUKHRUF_SESSION_ID_HEADER]: sessionId
|
|
3215
|
+
});
|
|
3216
|
+
}
|
|
3217
|
+
async function requireSession(runtime, conversation) {
|
|
3218
|
+
if (await runtime.sessionExists(conversation)) return;
|
|
3219
|
+
throw new HTTPException3(404, {
|
|
3220
|
+
message: "Session not found",
|
|
3221
|
+
cause: {
|
|
3222
|
+
code: "zukhruf/session-not-found",
|
|
3223
|
+
detail: `Session ${conversation.chatId} does not exist`
|
|
3224
|
+
}
|
|
3225
|
+
});
|
|
3226
|
+
}
|
|
3227
|
+
function methodNotAllowed(context, allow) {
|
|
3228
|
+
context.header("Allow", allow);
|
|
3229
|
+
throw new HTTPException3(405, {
|
|
3230
|
+
message: "Method not allowed",
|
|
3231
|
+
cause: {
|
|
3232
|
+
code: "api/method-not-allowed",
|
|
3233
|
+
detail: `This endpoint only accepts ${allow} requests`
|
|
3234
|
+
}
|
|
3235
|
+
});
|
|
3236
|
+
}
|
|
3237
|
+
|
|
2713
3238
|
// packages/experimental/src/zukhruf/queue/pg-boss.turn-queue.ts
|
|
2714
3239
|
import { v7 as uuidv7 } from "uuid";
|
|
2715
3240
|
|
|
@@ -3077,11 +3602,20 @@ async function renderTurn(stream) {
|
|
|
3077
3602
|
}
|
|
3078
3603
|
|
|
3079
3604
|
// packages/experimental/src/zukhruf/sandbox/define.ts
|
|
3080
|
-
import {
|
|
3081
|
-
|
|
3082
|
-
} from "@deepagents/context";
|
|
3605
|
+
import { createBashTool } from "@deepagents/context";
|
|
3606
|
+
var DEFAULT_WORKING_DIRECTORY = "/workspace";
|
|
3083
3607
|
function defineSandbox(createBackend, options) {
|
|
3084
|
-
return async (context) =>
|
|
3608
|
+
return async (context) => {
|
|
3609
|
+
const workingDirectory = options?.destination ?? DEFAULT_WORKING_DIRECTORY;
|
|
3610
|
+
return Object.assign(
|
|
3611
|
+
await createBashTool({
|
|
3612
|
+
sandbox: await createBackend(context),
|
|
3613
|
+
...options,
|
|
3614
|
+
destination: workingDirectory
|
|
3615
|
+
}),
|
|
3616
|
+
{ workingDirectory }
|
|
3617
|
+
);
|
|
3618
|
+
};
|
|
3085
3619
|
}
|
|
3086
3620
|
|
|
3087
3621
|
// packages/experimental/src/zukhruf/tool.ts
|