@parlor/chat 0.4.0 → 0.4.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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +17 -0
- package/dist/limits.d.ts.map +1 -1
- package/dist/limits.js +45 -0
- package/dist/limits.js.map +1 -1
- package/dist/server/actions.d.ts +49 -8
- package/dist/server/actions.d.ts.map +1 -1
- package/dist/server/actions.js +12 -5
- package/dist/server/actions.js.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/live.d.ts +2 -2
- package/dist/server/live.js +4 -4
- package/dist/server/live.js.map +1 -1
- package/dist/server/party.js +1 -1
- package/dist/server/party.js.map +1 -1
- package/dist/server/routes.d.ts.map +1 -1
- package/dist/server/routes.js +1 -2
- package/dist/server/routes.js.map +1 -1
- package/dist/server/rows.d.ts +12 -2
- package/dist/server/rows.d.ts.map +1 -1
- package/dist/server/rows.js +17 -9
- package/dist/server/rows.js.map +1 -1
- package/dist/server/store.d.ts +14 -2
- package/dist/server/store.d.ts.map +1 -1
- package/dist/server/store.js +27 -18
- package/dist/server/store.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { CHAT_EVENTS, type ChatEvent } from "./events.js";
|
|
2
2
|
export type { Author, AuthorOf, ChatItemBody, ChatItemKind, HostItemDraft, HostItemKind, ItemSignature, LoggedItem, UserItemKind, } from "./items.js";
|
|
3
3
|
export { type AppliedFrame, applyFrame } from "./open-turns.js";
|
|
4
|
-
export { isPromptTooLong, MAX_PROMPT_CHARS, PROMPT_LIMIT_MESSAGE } from "./limits.js";
|
|
4
|
+
export { AGENT_OPTION_LIMITS, clipAgentOptions, isPromptTooLong, MAX_PROMPT_CHARS, PROMPT_LIMIT_MESSAGE, } from "./limits.js";
|
|
5
5
|
export type { AgentInfo, AgentOption, AgentOptionValue, AgentRef, AgentUsage, AgentUsageWindow, AnswerToSign, ChatOwner, ChatSnapshot, ClaimedDevice, ClaimedTurn, HostSummary, OpenItem, OpenTurn, PromptToSign, ThreadHistory, ThreadList, ThreadPage, ThreadSummary, TurnFailure, TurnOutcome, TurnSignals, TurnState, TurnStatus, } from "./model.js";
|
|
6
6
|
export { CHAT_CHANNEL, CHAT_PLUGIN, type ChatFrame, HOST_PROTOCOL, type HostFrame, type HostHello, type HostStreamBatch, type HostWelcome, parseChatFrame, PUSHED_TURNS_PROTOCOL, type PushedTurn, type ProtocolRange, type StreamingKind, } from "./protocol.js";
|
|
7
7
|
export { CHAT_ACTIVITY_TAG, CHAT_AGENTS_CHECK_TAG, CHAT_TAG, HOSTS_TAG } from "./tags.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC1D,YAAY,EACV,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,aAAa,EACb,UAAU,EACV,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC1D,YAAY,EACV,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,aAAa,EACb,UAAU,EACV,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,UAAU,EACV,UAAU,EACV,aAAa,EACb,WAAW,EACX,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,YAAY,EACZ,WAAW,EACX,KAAK,SAAS,EACd,aAAa,EACb,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,cAAc,EACd,qBAAqB,EACrB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC1F,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,SAAS,EACd,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,kBAAkB,GACxB,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { CHAT_EVENTS } from "./events.js";
|
|
2
2
|
export { applyFrame } from "./open-turns.js";
|
|
3
|
-
export { isPromptTooLong, MAX_PROMPT_CHARS, PROMPT_LIMIT_MESSAGE } from "./limits.js";
|
|
3
|
+
export { AGENT_OPTION_LIMITS, clipAgentOptions, isPromptTooLong, MAX_PROMPT_CHARS, PROMPT_LIMIT_MESSAGE, } from "./limits.js";
|
|
4
4
|
export { CHAT_CHANNEL, CHAT_PLUGIN, HOST_PROTOCOL, parseChatFrame, PUSHED_TURNS_PROTOCOL, } from "./protocol.js";
|
|
5
5
|
export { CHAT_ACTIVITY_TAG, CHAT_AGENTS_CHECK_TAG, CHAT_TAG, HOSTS_TAG } from "./tags.js";
|
|
6
6
|
export { foldThread, } from "./view.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAY1D,OAAO,EAAqB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAY1D,OAAO,EAAqB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AA2BrB,OAAO,EACL,YAAY,EACZ,WAAW,EAEX,aAAa,EAKb,cAAc,EACd,qBAAqB,GAItB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC1F,OAAO,EAKL,UAAU,GAGX,MAAM,WAAW,CAAC","sourcesContent":["export { CHAT_EVENTS, type ChatEvent } from \"./events.js\";\nexport type {\n Author,\n AuthorOf,\n ChatItemBody,\n ChatItemKind,\n HostItemDraft,\n HostItemKind,\n ItemSignature,\n LoggedItem,\n UserItemKind,\n} from \"./items.js\";\nexport { type AppliedFrame, applyFrame } from \"./open-turns.js\";\nexport {\n AGENT_OPTION_LIMITS,\n clipAgentOptions,\n isPromptTooLong,\n MAX_PROMPT_CHARS,\n PROMPT_LIMIT_MESSAGE,\n} from \"./limits.js\";\nexport type {\n AgentInfo,\n AgentOption,\n AgentOptionValue,\n AgentRef,\n AgentUsage,\n AgentUsageWindow,\n AnswerToSign,\n ChatOwner,\n ChatSnapshot,\n ClaimedDevice,\n ClaimedTurn,\n HostSummary,\n OpenItem,\n OpenTurn,\n PromptToSign,\n ThreadHistory,\n ThreadList,\n ThreadPage,\n ThreadSummary,\n TurnFailure,\n TurnOutcome,\n TurnSignals,\n TurnState,\n TurnStatus,\n} from \"./model.js\";\nexport {\n CHAT_CHANNEL,\n CHAT_PLUGIN,\n type ChatFrame,\n HOST_PROTOCOL,\n type HostFrame,\n type HostHello,\n type HostStreamBatch,\n type HostWelcome,\n parseChatFrame,\n PUSHED_TURNS_PROTOCOL,\n type PushedTurn,\n type ProtocolRange,\n type StreamingKind,\n} from \"./protocol.js\";\nexport { CHAT_ACTIVITY_TAG, CHAT_AGENTS_CHECK_TAG, CHAT_TAG, HOSTS_TAG } from \"./tags.js\";\nexport {\n type AskState,\n type ChatItem,\n type FoldedKind,\n type FoldInput,\n foldThread,\n type ItemFolders,\n type ThreadConfirmation,\n} from \"./view.js\";\n"]}
|
package/dist/limits.d.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
+
import type { AgentOption } from "./model.js";
|
|
1
2
|
export declare const MAX_PROMPT_CHARS = 32000;
|
|
2
3
|
export declare const PROMPT_LIMIT_MESSAGE: string;
|
|
3
4
|
export declare const isPromptTooLong: (text: string) => boolean;
|
|
5
|
+
/** What a computer may report of one agent's options; longer display text is cut, never refused. */
|
|
6
|
+
export declare const AGENT_OPTION_LIMITS: {
|
|
7
|
+
readonly options: 10;
|
|
8
|
+
readonly values: 50;
|
|
9
|
+
readonly id: 200;
|
|
10
|
+
readonly optionName: 100;
|
|
11
|
+
readonly category: 50;
|
|
12
|
+
readonly valueName: 200;
|
|
13
|
+
readonly description: 500;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* An agent's options within `AGENT_OPTION_LIMITS`: names and descriptions cut to length, the
|
|
17
|
+
* first values kept with the current one among them, and an option or value whose id is too
|
|
18
|
+
* long to send back dropped, as choosing it could not work.
|
|
19
|
+
*/
|
|
20
|
+
export declare function clipAgentOptions(options: readonly AgentOption[]): AgentOption[];
|
|
4
21
|
//# sourceMappingURL=limits.d.ts.map
|
package/dist/limits.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAEvC,eAAO,MAAM,oBAAoB,QAAoF,CAAC;AAEtH,eAAO,MAAM,eAAe,SAAU,MAAM,KAAG,OACR,CAAC"}
|
|
1
|
+
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,YAAY,CAAC;AAEhE,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAEvC,eAAO,MAAM,oBAAoB,QAAoF,CAAC;AAEtH,eAAO,MAAM,eAAe,SAAU,MAAM,KAAG,OACR,CAAC;AAExC,oGAAoG;AACpG,eAAO,MAAM,mBAAmB;aAC9B,OAAO,EAAE,EAAE;aACX,MAAM,EAAE,EAAE;aACV,EAAE,EAAE,GAAG;aACP,UAAU,EAAE,GAAG;aACf,QAAQ,EAAE,EAAE;aACZ,SAAS,EAAE,GAAG;aACd,WAAW,EAAE,GAAG;CACR,CAAC;AAKX;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,GAAG,WAAW,EAAE,CA+B/E"}
|
package/dist/limits.js
CHANGED
|
@@ -1,4 +1,49 @@
|
|
|
1
1
|
export const MAX_PROMPT_CHARS = 32_000;
|
|
2
2
|
export const PROMPT_LIMIT_MESSAGE = `Messages can be at most ${MAX_PROMPT_CHARS.toLocaleString("en-US")} characters.`;
|
|
3
3
|
export const isPromptTooLong = (text) => text.trim().length > MAX_PROMPT_CHARS;
|
|
4
|
+
/** What a computer may report of one agent's options; longer display text is cut, never refused. */
|
|
5
|
+
export const AGENT_OPTION_LIMITS = {
|
|
6
|
+
options: 10,
|
|
7
|
+
values: 50,
|
|
8
|
+
id: 200,
|
|
9
|
+
optionName: 100,
|
|
10
|
+
category: 50,
|
|
11
|
+
valueName: 200,
|
|
12
|
+
description: 500,
|
|
13
|
+
};
|
|
14
|
+
const clip = (text, max) => text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
15
|
+
/**
|
|
16
|
+
* An agent's options within `AGENT_OPTION_LIMITS`: names and descriptions cut to length, the
|
|
17
|
+
* first values kept with the current one among them, and an option or value whose id is too
|
|
18
|
+
* long to send back dropped, as choosing it could not work.
|
|
19
|
+
*/
|
|
20
|
+
export function clipAgentOptions(options) {
|
|
21
|
+
const limits = AGENT_OPTION_LIMITS;
|
|
22
|
+
return options
|
|
23
|
+
.filter((option) => option.id.length <= limits.id && option.current.length <= limits.id)
|
|
24
|
+
.slice(0, limits.options)
|
|
25
|
+
.map((option) => {
|
|
26
|
+
const fitting = option.values.filter((value) => value.id.length <= limits.id);
|
|
27
|
+
const current = fitting.find((value) => value.id === option.current);
|
|
28
|
+
const first = fitting.slice(0, limits.values);
|
|
29
|
+
const kept = current && !first.includes(current)
|
|
30
|
+
? [...first.slice(0, limits.values - 1), current]
|
|
31
|
+
: first;
|
|
32
|
+
return {
|
|
33
|
+
id: option.id,
|
|
34
|
+
name: clip(option.name, limits.optionName),
|
|
35
|
+
...(option.category === undefined
|
|
36
|
+
? {}
|
|
37
|
+
: { category: clip(option.category, limits.category) }),
|
|
38
|
+
current: option.current,
|
|
39
|
+
values: kept.map((value) => ({
|
|
40
|
+
id: value.id,
|
|
41
|
+
name: clip(value.name, limits.valueName),
|
|
42
|
+
...(value.description === undefined
|
|
43
|
+
? {}
|
|
44
|
+
: { description: clip(value.description, limits.description) }),
|
|
45
|
+
})),
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
4
49
|
//# sourceMappingURL=limits.js.map
|
package/dist/limits.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limits.js","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"limits.js","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,2BAA2B,gBAAgB,CAAC,cAAc,CAAC,OAAO,CAAC,cAAc,CAAC;AAEtH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAW,EAAE,CACvD,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,gBAAgB,CAAC;AAExC,oGAAoG;AACpG,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,OAAO,EAAE,EAAE;IACX,MAAM,EAAE,EAAE;IACV,EAAE,EAAE,GAAG;IACP,UAAU,EAAE,GAAG;IACf,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,GAAG;IACd,WAAW,EAAE,GAAG;CACR,CAAC;AAEX,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,GAAW,EAAE,EAAE,CACzC,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAE1D;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA+B;IAC9D,MAAM,MAAM,GAAG,mBAAmB,CAAC;IACnC,OAAO,OAAO;SACX,MAAM,CACL,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,IAAI,MAAM,C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AAK,CAAC,EAAE;gBACZ,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC;gBACxC,GAAG,CAAC,KAAK,CAAC,WAAW,KAAK,SAAS;oBACjC,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;aAClE,CAAC,CAAC;SACJ,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { AgentOption, AgentOptionValue } from \"./model.js\";\n\nexport const MAX_PROMPT_CHARS = 32_000;\n\nexport const PROMPT_LIMIT_MESSAGE = `Messages can be at most ${MAX_PROMPT_CHARS.toLocaleString(\"en-US\")} characters.`;\n\nexport const isPromptTooLong = (text: string): boolean =>\n text.trim().length > MAX_PROMPT_CHARS;\n\n/** What a computer may report of one agent's options; longer display text is cut, never refused. */\nexport const AGENT_OPTION_LIMITS = {\n options: 10,\n values: 50,\n id: 200,\n optionName: 100,\n category: 50,\n valueName: 200,\n description: 500,\n} as const;\n\nconst clip = (text: string, max: number) =>\n text.length > max ? `${text.slice(0, max - 1)}…` : text;\n\n/**\n * An agent's options within `AGENT_OPTION_LIMITS`: names and descriptions cut to length, the\n * first values kept with the current one among them, and an option or value whose id is too\n * long to send back dropped, as choosing it could not work.\n */\nexport function clipAgentOptions(options: readonly AgentOption[]): AgentOption[] {\n const limits = AGENT_OPTION_LIMITS;\n return options\n .filter(\n (option) => option.id.length <= limits.id && option.current.length <= limits.id,\n )\n .slice(0, limits.options)\n .map((option) => {\n const fitting = option.values.filter((value) => value.id.length <= limits.id);\n const current = fitting.find((value) => value.id === option.current);\n const first = fitting.slice(0, limits.values);\n const kept =\n current && !first.includes(current)\n ? [...first.slice(0, limits.values - 1), current]\n : first;\n return {\n id: option.id,\n name: clip(option.name, limits.optionName),\n ...(option.category === undefined\n ? {}\n : { category: clip(option.category, limits.category) }),\n current: option.current,\n values: kept.map((value): AgentOptionValue => ({\n id: value.id,\n name: clip(value.name, limits.valueName),\n ...(value.description === undefined\n ? {}\n : { description: clip(value.description, limits.description) }),\n })),\n };\n });\n}\n"]}
|
package/dist/server/actions.d.ts
CHANGED
|
@@ -158,6 +158,7 @@ export declare function hostSession(deps: ChatActionDeps): {
|
|
|
158
158
|
turnId: TurnId;
|
|
159
159
|
clientId: string;
|
|
160
160
|
agentId: string;
|
|
161
|
+
scope: string;
|
|
161
162
|
}) => Promise<Delegation>;
|
|
162
163
|
claim: (host: ChatHost, db: ChatDb) => Promise<ClaimedTurn | undefined>;
|
|
163
164
|
release: (host: ChatHost, thread: ThreadId, turn: TurnId) => Promise<boolean>;
|
|
@@ -180,7 +181,7 @@ export declare function hostChatActions(deps: ChatActionDeps, session?: HostSess
|
|
|
180
181
|
version: z.ZodOptional<z.ZodString>;
|
|
181
182
|
ready: z.ZodBoolean;
|
|
182
183
|
problem: z.ZodOptional<z.ZodString>;
|
|
183
|
-
options: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
184
|
+
options: z.ZodOptional<z.ZodReadonly<z.ZodPipe<z.ZodArray<z.ZodObject<{
|
|
184
185
|
id: z.ZodString;
|
|
185
186
|
name: z.ZodString;
|
|
186
187
|
category: z.ZodOptional<z.ZodString>;
|
|
@@ -190,7 +191,17 @@ export declare function hostChatActions(deps: ChatActionDeps, session?: HostSess
|
|
|
190
191
|
name: z.ZodString;
|
|
191
192
|
description: z.ZodOptional<z.ZodString>;
|
|
192
193
|
}, z.core.$strip>>>;
|
|
193
|
-
}, z.core.$strip
|
|
194
|
+
}, z.core.$strip>>, z.ZodTransform<import("../model.js").AgentOption[], {
|
|
195
|
+
id: string;
|
|
196
|
+
name: string;
|
|
197
|
+
category?: string | undefined;
|
|
198
|
+
current: string;
|
|
199
|
+
values: readonly {
|
|
200
|
+
id: string;
|
|
201
|
+
name: string;
|
|
202
|
+
description?: string | undefined;
|
|
203
|
+
}[];
|
|
204
|
+
}[]>>>>;
|
|
194
205
|
usage: z.ZodOptional<z.ZodObject<{
|
|
195
206
|
windows: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
196
207
|
id: z.ZodString;
|
|
@@ -215,7 +226,7 @@ export declare function hostChatActions(deps: ChatActionDeps, session?: HostSess
|
|
|
215
226
|
version: z.ZodOptional<z.ZodString>;
|
|
216
227
|
ready: z.ZodBoolean;
|
|
217
228
|
problem: z.ZodOptional<z.ZodString>;
|
|
218
|
-
options: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
229
|
+
options: z.ZodOptional<z.ZodReadonly<z.ZodPipe<z.ZodArray<z.ZodObject<{
|
|
219
230
|
id: z.ZodString;
|
|
220
231
|
name: z.ZodString;
|
|
221
232
|
category: z.ZodOptional<z.ZodString>;
|
|
@@ -225,7 +236,17 @@ export declare function hostChatActions(deps: ChatActionDeps, session?: HostSess
|
|
|
225
236
|
name: z.ZodString;
|
|
226
237
|
description: z.ZodOptional<z.ZodString>;
|
|
227
238
|
}, z.core.$strip>>>;
|
|
228
|
-
}, z.core.$strip
|
|
239
|
+
}, z.core.$strip>>, z.ZodTransform<import("../model.js").AgentOption[], {
|
|
240
|
+
id: string;
|
|
241
|
+
name: string;
|
|
242
|
+
category?: string | undefined;
|
|
243
|
+
current: string;
|
|
244
|
+
values: readonly {
|
|
245
|
+
id: string;
|
|
246
|
+
name: string;
|
|
247
|
+
description?: string | undefined;
|
|
248
|
+
}[];
|
|
249
|
+
}[]>>>>;
|
|
229
250
|
usage: z.ZodOptional<z.ZodObject<{
|
|
230
251
|
windows: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
231
252
|
id: z.ZodString;
|
|
@@ -490,7 +511,7 @@ export declare function chatActions(deps: ChatActionDeps, session?: HostSession)
|
|
|
490
511
|
version: z.ZodOptional<z.ZodString>;
|
|
491
512
|
ready: z.ZodBoolean;
|
|
492
513
|
problem: z.ZodOptional<z.ZodString>;
|
|
493
|
-
options: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
514
|
+
options: z.ZodOptional<z.ZodReadonly<z.ZodPipe<z.ZodArray<z.ZodObject<{
|
|
494
515
|
id: z.ZodString;
|
|
495
516
|
name: z.ZodString;
|
|
496
517
|
category: z.ZodOptional<z.ZodString>;
|
|
@@ -500,7 +521,17 @@ export declare function chatActions(deps: ChatActionDeps, session?: HostSession)
|
|
|
500
521
|
name: z.ZodString;
|
|
501
522
|
description: z.ZodOptional<z.ZodString>;
|
|
502
523
|
}, z.core.$strip>>>;
|
|
503
|
-
}, z.core.$strip
|
|
524
|
+
}, z.core.$strip>>, z.ZodTransform<import("../model.js").AgentOption[], {
|
|
525
|
+
id: string;
|
|
526
|
+
name: string;
|
|
527
|
+
category?: string | undefined;
|
|
528
|
+
current: string;
|
|
529
|
+
values: readonly {
|
|
530
|
+
id: string;
|
|
531
|
+
name: string;
|
|
532
|
+
description?: string | undefined;
|
|
533
|
+
}[];
|
|
534
|
+
}[]>>>>;
|
|
504
535
|
usage: z.ZodOptional<z.ZodObject<{
|
|
505
536
|
windows: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
506
537
|
id: z.ZodString;
|
|
@@ -525,7 +556,7 @@ export declare function chatActions(deps: ChatActionDeps, session?: HostSession)
|
|
|
525
556
|
version: z.ZodOptional<z.ZodString>;
|
|
526
557
|
ready: z.ZodBoolean;
|
|
527
558
|
problem: z.ZodOptional<z.ZodString>;
|
|
528
|
-
options: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
559
|
+
options: z.ZodOptional<z.ZodReadonly<z.ZodPipe<z.ZodArray<z.ZodObject<{
|
|
529
560
|
id: z.ZodString;
|
|
530
561
|
name: z.ZodString;
|
|
531
562
|
category: z.ZodOptional<z.ZodString>;
|
|
@@ -535,7 +566,17 @@ export declare function chatActions(deps: ChatActionDeps, session?: HostSession)
|
|
|
535
566
|
name: z.ZodString;
|
|
536
567
|
description: z.ZodOptional<z.ZodString>;
|
|
537
568
|
}, z.core.$strip>>>;
|
|
538
|
-
}, z.core.$strip
|
|
569
|
+
}, z.core.$strip>>, z.ZodTransform<import("../model.js").AgentOption[], {
|
|
570
|
+
id: string;
|
|
571
|
+
name: string;
|
|
572
|
+
category?: string | undefined;
|
|
573
|
+
current: string;
|
|
574
|
+
values: readonly {
|
|
575
|
+
id: string;
|
|
576
|
+
name: string;
|
|
577
|
+
description?: string | undefined;
|
|
578
|
+
}[];
|
|
579
|
+
}[]>>>>;
|
|
539
580
|
usage: z.ZodOptional<z.ZodObject<{
|
|
540
581
|
windows: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
541
582
|
id: z.ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/server/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,MAAM,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,SAAS,EAAkB,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAiC,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACb,UAAU,EACV,WAAW,EACX,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAiB,KAAK,WAAW,EAAyB,MAAM,gBAAgB,CAAC;AACxF,OAAO,EACL,iBAAiB,EAEjB,QAAQ,EACR,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,SAAS,EA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+IiC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgDhD,MAAM;8BAAwB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAiF/C,MAAM;6BACE,MAAM;wBACX,WAAW,CAAC,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;qBAoCgB,MAAM;;GA6BjE;AAED,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAChE,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,kBAAkB,CAAC,CAAC;AAC1D,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AACnE,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
package/dist/server/actions.js
CHANGED
|
@@ -245,18 +245,20 @@ export function hostSession(deps) {
|
|
|
245
245
|
clientId: turn.clientId,
|
|
246
246
|
agent: await agentNameOf(host, db, turn.agentId),
|
|
247
247
|
ttlMs: deps.leaseMs,
|
|
248
|
+
scope: turn.scope,
|
|
248
249
|
});
|
|
249
250
|
};
|
|
250
251
|
/** The next turn waiting for `host`, claimed for it with its token and context; undefined when none waits. */
|
|
251
252
|
const claim = async (host, db) => {
|
|
252
253
|
await requireWelcome(host, db);
|
|
253
254
|
await deps.reconcile(host);
|
|
254
|
-
const
|
|
255
|
+
const stored = await deps.transact(host, async (tx) => {
|
|
255
256
|
const taken = await deps.store.claimTurn(tx, host, host.host, deps.leaseMs);
|
|
256
257
|
return { result: taken, threadId: taken?.id };
|
|
257
258
|
});
|
|
258
|
-
if (!
|
|
259
|
+
if (!stored)
|
|
259
260
|
return undefined;
|
|
261
|
+
const { owner = host, ...claimed } = stored;
|
|
260
262
|
try {
|
|
261
263
|
const deviceId = claimed.prompt.body.signed?.deviceId;
|
|
262
264
|
const [token, device, account, page] = await Promise.all([
|
|
@@ -265,10 +267,11 @@ export function hostSession(deps) {
|
|
|
265
267
|
turnId: claimed.turnId,
|
|
266
268
|
clientId: claimed.clientId,
|
|
267
269
|
agentId: claimed.agent.agentId,
|
|
270
|
+
scope: owner.scope,
|
|
268
271
|
}),
|
|
269
272
|
deviceId ? deps.auth.device?.(host.userId, deviceId) : undefined,
|
|
270
273
|
deps.auth.account?.(host.userId),
|
|
271
|
-
deps.store.readPage(db,
|
|
274
|
+
deps.store.readPage(db, owner, claimed.id, CONTEXT_HISTORY_ITEMS),
|
|
272
275
|
]);
|
|
273
276
|
const context = turnContext({
|
|
274
277
|
appName: deps.appName,
|
|
@@ -436,7 +439,11 @@ export function hostChatActions(deps, session = hostSession(deps)) {
|
|
|
436
439
|
threadId: input.items.length > 0 ? result.threadId : undefined,
|
|
437
440
|
};
|
|
438
441
|
});
|
|
439
|
-
const token = await mint(host, dbOf(ctx), {
|
|
442
|
+
const token = await mint(host, dbOf(ctx), {
|
|
443
|
+
...appended,
|
|
444
|
+
turnId: input.turnId,
|
|
445
|
+
scope: (appended.owner ?? host).scope,
|
|
446
|
+
});
|
|
440
447
|
return { id: appended.threadId, leaseUntil: appended.leaseUntil, token };
|
|
441
448
|
},
|
|
442
449
|
}),
|
|
@@ -457,7 +464,7 @@ export function hostChatActions(deps, session = hostSession(deps)) {
|
|
|
457
464
|
const result = await deps.store.finishTurn(tx, host, host.host, input.turnId, input.outcome);
|
|
458
465
|
return { result, threadId: result.threadId };
|
|
459
466
|
});
|
|
460
|
-
deps.relay.settle(host, finished.threadId, input.turnId);
|
|
467
|
+
deps.relay.settle(finished.owner ?? host, finished.threadId, input.turnId);
|
|
461
468
|
return { id: finished.threadId };
|
|
462
469
|
},
|
|
463
470
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/server/actions.ts"],"names":[],"mappings":"AAAA,O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AAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;iBACxE,CAAC;aACH,CAAC;YACF,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAoC,EAAE;gBAChE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACnC,MAAM,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;gBACtC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;oBACtD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CACxC,EAAE,EACF,IAAI,EACJ,IAAI,CAAC,IAAI,EACT,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,OAAO,CACd,CAAC;oBACF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;gBAC/C,CAAC,CAAC,CAAC;gBACH,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;gBACzD,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACnC,CAAC;SACF,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,IAAoB,EACpB,OAAO,GAAgB,WAAW,CAAC,IAAI,CAAC;IAExC,OAAO,cAAc,CAAC,EAAE,GAAG,eAAe,CAAC,IAAI,CAAC,EAAE,GAAG,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;AACzF,CAAC","sourcesContent":["import {\n type ActionContext,\n ActionError,\n type HostId,\n type ThreadId,\n type TurnId,\n} from \"@parlor/core\";\nimport { type ActionsOf, createRegistry } from \"@parlor/core/registry\";\nimport { type AuthProvider, type Delegation, HOST_GRANTS_TAG } from \"@parlor/server\";\nimport { z } from \"zod\";\n\nimport { idSchema } from \"../id-schemas.js\";\nimport { chatItemBodies, hostItemDraft, type LoggedItem } from \"../items.js\";\nimport type {\n AgentInfo,\n ChatOwner,\n ChatSnapshot,\n ThreadHistory,\n ThreadList,\n ClaimedTurn,\n HostSummary,\n TurnSignals,\n} from \"../model.js\";\nimport { HOST_PROTOCOL, type HostWelcome, PUSHED_TURNS_PROTOCOL } from \"../protocol.js\";\nimport {\n CHAT_ACTIVITY_TAG,\n CHAT_AGENTS_CHECK_TAG,\n CHAT_TAG,\n HOSTS_TAG,\n} from \"../tags.js\";\nimport { turnContext } from \"./context.js\";\nimport type { LiveRelay } from \"./live.js\";\nimport { type ChatHost, chatAction } from \"./party.js\";\nimport type { TurnPush } from \"./push.js\";\nimport { agentInfoSchema, TURN_FAILURES } from \"./rows.js\";\n\nconst presenceDueSchema = z\n .record(z.string().min(1).max(64), z.number().int().nonnegative())\n .refine((due) => Object.keys(due).length <= 256, \"At most 256 devices.\");\nimport {\n type ChatDb,\n type ChatStore,\n type StoredHost,\n THREAD_LIST_LIMIT,\n} from \"./store.js\";\n\nexport { CHAT_ACTIVITY_TAG, CHAT_TAG, HOSTS_TAG, HOST_GRANTS_TAG };\n\nexport interface Written<T> {\n readonly result: T;\n readonly threadId: ThreadId | undefined;\n}\n\nexport interface ChatActionDeps {\n readonly enforcing: boolean;\n /**\n * Runs `work` in one transaction with the thread's sync event. Actions that call the auth\n * provider do so outside it, because a provider may read through another connection\n * (PGlite has one, and the transaction holds it).\n */\n /** Runs `work` in one transaction and wakes only `owner`'s tabs and computers. */\n readonly transact: <T>(\n owner: ChatOwner,\n work: (tx: ChatDb) => Promise<Written<T>>,\n ) => Promise<T>;\n /** Commits the lapsed leases and liveness of `owner`, with the sync events they owe. */\n readonly reconcile: (owner: ChatOwner) => Promise<void>;\n /** Drops the owner's computer rows whose grant is gone; best effort, never fails a read. */\n readonly pruneHosts: (owner: ChatOwner, hostIds: readonly HostId[]) => Promise<void>;\n readonly auth: AuthProvider;\n readonly store: ChatStore;\n readonly relay: LiveRelay;\n readonly leaseMs: number;\n readonly heartbeatMs: number;\n readonly maxQueued: number;\n readonly instructions: string | undefined;\n readonly appName: string;\n readonly appOrigin: () => string;\n /** Hands a queued turn straight to its computer; without it computers only claim. */\n readonly pushed?: TurnPush | undefined;\n}\n\nconst threadId = idSchema(\"thread\");\nconst turnId = idSchema(\"turn\");\nconst itemId = idSchema(\"item\");\nconst afterSeq = z.number().int().min(0);\n\nconst MIN_HOST_PROTOCOL = 2;\nconst CONTEXT_HISTORY_ITEMS = 200;\n/** An agent outside a turn asks again well inside the revocation horizon. */\nconst AGENT_TOKEN_TTL_MS = 10 * 60_000;\nconst TERMINAL: ReadonlySet<string> = new Set([\"done\", \"failed\", \"cancelled\"]);\n\nconst dbOf = (ctx: ActionContext) => ctx.db as ChatDb;\n\nasync function activeHosts(\n deps: ChatActionDeps,\n db: ChatDb,\n owner: ChatOwner,\n): Promise<StoredHost[]> {\n const hosts = await deps.store.listHosts(db, owner);\n const { hostActive } = deps.auth;\n if (!hostActive) return hosts;\n const holding = await Promise.all(\n hosts.map((host) => hostActive.call(deps.auth, host.grantId)),\n );\n const gone = hosts.filter((_host, at) => !holding[at]);\n if (gone.length > 0) {\n await deps.pruneHosts(\n owner,\n gone.map((host) => host.id),\n );\n }\n return hosts.filter((_host, at) => holding[at]);\n}\n\nconst summaryOf = ({\n grantId: _grantId,\n protocol: _protocol,\n ...summary\n}: StoredHost): HostSummary => summary;\n\nexport function userChatActions(deps: ChatActionDeps) {\n const { enforcing } = deps;\n return {\n open: chatAction(\"user\", enforcing, {\n description:\n \"The sidebar's first paint in one round trip: threads, computers, and a thread's last page with what streams now.\",\n input: z.object({\n threadId: threadId.optional(),\n limit: z.number().int().min(1).max(500).default(200),\n }),\n reads: (input) => [\n [CHAT_TAG, ...(input.threadId ? [input.threadId] : [])],\n [HOSTS_TAG],\n [HOST_GRANTS_TAG],\n ],\n run: async (input, user, ctx): Promise<ChatSnapshot> => {\n const db = dbOf(ctx);\n const [threads, hosts, page] = await Promise.all([\n deps.store.listThreads(db, user),\n activeHosts(deps, db, user),\n deps.store.readPage(db, user, input.threadId, input.limit),\n ]);\n const thread = page.thread;\n const open = thread ? deps.relay.open(user, thread.id) : [];\n const streaming = open.filter((turn) => {\n const state = page.turns.find((status) => status.turnId === turn.turnId)?.state;\n const ended = state !== undefined && TERMINAL.has(state);\n if (ended) deps.relay.settle(user, turn.threadId, turn.turnId);\n return !ended;\n });\n return {\n threads,\n ...(threads.length >= THREAD_LIST_LIMIT ? { moreThreads: true } : {}),\n hosts: hosts.map(summaryOf),\n page: { ...page, open: streaming },\n };\n },\n }),\n items: chatAction(\"user\", enforcing, {\n description: \"A thread's items after a sequence number.\",\n input: z.object({ threadId, afterSeq }),\n reads: (input) => [[CHAT_TAG, input.threadId]],\n run: (input, user, ctx): Promise<LoggedItem[]> =>\n deps.store.readItemsAfter(dbOf(ctx), user, input.threadId, input.afterSeq),\n }),\n history: chatAction(\"user\", enforcing, {\n description:\n \"A thread's items before a sequence number, oldest first, with their turns; hasMore while older ones remain.\",\n input: z.object({\n threadId,\n beforeSeq: z.number().int().min(1),\n limit: z.number().int().min(1).max(500).default(200),\n }),\n reads: (input) => [[CHAT_TAG, input.threadId]],\n run: async (input, user, ctx): Promise<ThreadHistory> => {\n const read = deps.store.readItemsBefore?.bind(deps.store);\n if (!read)\n throw new ActionError(\"not_found\", \"This chat store keeps no history.\");\n return read(dbOf(ctx), user, input.threadId, input.beforeSeq, input.limit);\n },\n }),\n threadsBefore: chatAction(\"user\", enforcing, {\n description:\n \"The user's threads updated before a thread, newest first, for the list past what open returned.\",\n input: z.object({\n before: z.object({ updatedAt: z.number().int().min(0), id: threadId }),\n limit: z.number().int().min(1).max(500).default(200),\n }),\n reads: [CHAT_TAG],\n run: async (input, user, ctx): Promise<ThreadList> => {\n const list = deps.store.listThreadsBefore?.bind(deps.store);\n if (!list)\n throw new ActionError(\"not_found\", \"This chat store keeps no history.\");\n return list(dbOf(ctx), user, input.before, input.limit);\n },\n }),\n hosts: chatAction(\"user\", enforcing, {\n description: \"The user's computers and the agents on them.\",\n input: z.object({}),\n reads: [HOSTS_TAG, HOST_GRANTS_TAG],\n run: async (_input, user, ctx): Promise<HostSummary[]> =>\n (await activeHosts(deps, dbOf(ctx), user)).map(summaryOf),\n }),\n send: chatAction(\"user\", enforcing, {\n description: \"Send a prompt to an agent on one of the user's computers.\",\n input: z.object({\n threadId,\n turnId,\n itemId,\n clientId: z.string().min(1).max(128),\n prompt: chatItemBodies.prompt.body,\n }),\n run: async (\n input,\n user,\n ctx,\n ): Promise<{ readonly id: string; readonly turnId: string }> => {\n const hosts = await activeHosts(deps, dbOf(ctx), user);\n const host = hosts.find(\n (candidate) => candidate.id === input.prompt.agent.hostId,\n );\n if (!host) throw new ActionError(\"not_found\", \"Computer not found\");\n const sent = await deps.transact(user, async (tx) => {\n await deps.store.appendUserItems(tx, user, {\n threadId: input.threadId,\n turnId: input.turnId,\n items: [{ id: input.itemId, kind: \"prompt\", body: input.prompt }],\n turn: {\n turnId: input.turnId,\n agent: input.prompt.agent,\n clientId: input.clientId,\n deviceId: user.deviceId,\n maxQueued: deps.maxQueued,\n },\n });\n return {\n result: { id: input.threadId, turnId: input.turnId },\n threadId: input.threadId,\n };\n });\n if (host.protocol >= PUSHED_TURNS_PROTOCOL) deps.pushed?.offer(user, host.id);\n return sent;\n },\n }),\n answer: chatAction(\"user\", enforcing, {\n description: \"Answer the agent's permission prompt or question.\",\n input: z.object({ threadId, turnId, itemId, answer: chatItemBodies.answer.body }),\n run: async (input, user): Promise<{ readonly id: string }> => {\n const { signed } = input.answer;\n if (signed && deps.auth.device) {\n const device = await deps.auth.device(user.userId, signed.deviceId);\n if (!device) {\n throw new ActionError(\"forbidden\", \"This device cannot answer.\");\n }\n }\n return deps.transact(user, async (tx) => {\n await deps.store.appendUserItems(tx, user, {\n threadId: input.threadId,\n turnId: input.turnId,\n items: [{ id: input.itemId, kind: \"answer\", body: input.answer }],\n });\n return { result: { id: input.threadId }, threadId: input.threadId };\n });\n },\n }),\n cancel: chatAction(\"user\", enforcing, {\n description: \"Stop the running turn; what the agent already said is kept.\",\n input: z.object({ threadId, turnId, itemId }),\n writes: [CHAT_TAG],\n run: async (input, user, ctx): Promise<{ readonly id: string }> => {\n await deps.store.appendUserItems(dbOf(ctx), user, {\n threadId: input.threadId,\n turnId: input.turnId,\n items: [{ id: input.itemId, kind: \"cancel\", body: {} }],\n });\n return { id: input.threadId };\n },\n }),\n userActive: chatAction(\"user\", enforcing, {\n description:\n \"Tell the user's computers a tab is in use, so a polling computer speeds up; carries no content and writes no table.\",\n input: z.object({}),\n writes: [CHAT_ACTIVITY_TAG],\n run: (): { readonly ok: true } => ({ ok: true }),\n }),\n checkAgents: chatAction(\"user\", enforcing, {\n description:\n \"Ask the user's computers to look again for the coding agents installed on them; each reports what it found, stamped `agentsCheckedAt`. Answers when it asked, by the same clock.\",\n input: z.object({}),\n writes: [CHAT_AGENTS_CHECK_TAG],\n run: (): { readonly askedAt: number } => ({ askedAt: Date.now() }),\n }),\n };\n}\n\n/**\n * What the server keeps about the computers it serves: which said hello, their agents'\n * names, and how a turn is claimed for one, by `hostClaim` or pushed to it.\n */\nexport function hostSession(deps: ChatActionDeps) {\n const welcomed = new Set<HostId>();\n const welcome = async (host: ChatHost, db: ChatDb) => {\n const hosts = await deps.store.listHosts(db, host);\n const known = hosts.find((candidate) => candidate.id === host.host.hostId);\n if (!known) throw new ActionError(\"forbidden\", \"Say hello before anything else.\");\n if (known.protocol < MIN_HOST_PROTOCOL) {\n await deps.pruneHosts(host, [known.id]);\n throw new ActionError(\"forbidden\", \"Say hello before anything else.\");\n }\n welcomed.add(known.id);\n return known;\n };\n const requireWelcome = async (host: ChatHost, db: ChatDb) => {\n if (!welcomed.has(host.host.hostId)) await welcome(host, db);\n };\n const agentNames = new Map<HostId, ReadonlyMap<string, string>>();\n const learnAgents = (hostId: HostId, agents: readonly AgentInfo[]) => {\n agentNames.set(hostId, new Map(agents.map((agent) => [agent.id, agent.name])));\n };\n const agentNameOf = async (host: ChatHost, db: ChatDb, agentId: string) => {\n if (!agentNames.has(host.host.hostId)) {\n const known = (await deps.store.listHosts(db, host)).find(\n (candidate) => candidate.id === host.host.hostId,\n );\n if (known) learnAgents(known.id, known.agents);\n }\n return agentNames.get(host.host.hostId)?.get(agentId) ?? agentId;\n };\n const mint = async (\n host: ChatHost,\n db: ChatDb,\n turn: { threadId: ThreadId; turnId: TurnId; clientId: string; agentId: string },\n ) => {\n if (!deps.auth.delegate) {\n throw new ActionError(\"internal\", \"The auth provider cannot mint turn tokens.\");\n }\n return deps.auth.delegate(host.host, {\n threadId: turn.threadId,\n turnId: turn.turnId,\n clientId: turn.clientId,\n agent: await agentNameOf(host, db, turn.agentId),\n ttlMs: deps.leaseMs,\n });\n };\n /** The next turn waiting for `host`, claimed for it with its token and context; undefined when none waits. */\n const claim = async (host: ChatHost, db: ChatDb): Promise<ClaimedTurn | undefined> => {\n await requireWelcome(host, db);\n await deps.reconcile(host);\n const claimed = await deps.transact(host, async (tx) => {\n const taken = await deps.store.claimTurn(tx, host, host.host, deps.leaseMs);\n return { result: taken, threadId: taken?.id };\n });\n if (!claimed) return undefined;\n try {\n const deviceId = claimed.prompt.body.signed?.deviceId;\n const [token, device, account, page] = await Promise.all([\n mint(host, db, {\n threadId: claimed.id,\n turnId: claimed.turnId,\n clientId: claimed.clientId,\n agentId: claimed.agent.agentId,\n }),\n deviceId ? deps.auth.device?.(host.userId, deviceId) : undefined,\n deps.auth.account?.(host.userId),\n deps.store.readPage(db, host, claimed.id, CONTEXT_HISTORY_ITEMS),\n ]);\n const context = turnContext({\n appName: deps.appName,\n appOrigin: deps.appOrigin(),\n account,\n device,\n instructions: deps.instructions,\n history: page.items.filter((item) => item.seq < claimed.prompt.seq),\n });\n return { ...claimed, device, context, token };\n } catch (error) {\n await release(host, claimed.id, claimed.turnId).catch(() => false);\n throw error;\n }\n };\n /** Puts a claimed turn back in the queue, waking the computer to claim it again. */\n const release = (host: ChatHost, thread: ThreadId, turn: TurnId) =>\n deps.transact(host, async (tx) => {\n const released = await deps.store.releaseClaim(tx, host, host.host, turn);\n return { result: released, threadId: thread };\n });\n return {\n welcome,\n requireWelcome,\n learnAgents,\n agentNameOf,\n mint,\n claim,\n release,\n welcomed,\n };\n}\n\nexport type HostSession = ReturnType<typeof hostSession>;\n\n/** What the user's computers call; `hostHello` first on every link. */\nexport function hostChatActions(\n deps: ChatActionDeps,\n session: HostSession = hostSession(deps),\n) {\n const { enforcing } = deps;\n const { welcome, requireWelcome, learnAgents, mint, welcomed } = session;\n return {\n hostHello: chatAction(\"host\", enforcing, {\n description:\n \"A link's first call: agree on the host protocol and report this computer online with its agents.\",\n input: z.object({\n protocols: z.object({\n min: z.number().int().min(1),\n max: z.number().int().min(1),\n }),\n hostVersion: z.string().min(1).max(32),\n name: z.string().min(1).max(80),\n platform: z.string().min(1).max(32),\n agents: z.array(agentInfoSchema).max(32),\n devices: z.array(z.string().min(1).max(64)).max(256).optional(),\n presenceDue: presenceDueSchema.optional(),\n }),\n writes: [HOSTS_TAG],\n run: async (input, host, ctx): Promise<HostWelcome & { readonly id: string }> => {\n const id = host.host.hostId;\n const protocols = { min: MIN_HOST_PROTOCOL, max: HOST_PROTOCOL };\n const refuse = async (reason: \"host_too_old\" | \"app_too_old\") => {\n welcomed.delete(id);\n await deps.store.pruneHosts(dbOf(ctx), host, [id]);\n return { id, accepted: false as const, reason, protocols };\n };\n if (input.protocols.max < protocols.min) return refuse(\"host_too_old\");\n const protocol = Math.min(input.protocols.max, protocols.max);\n if (protocol < input.protocols.min) return refuse(\"app_too_old\");\n await deps.store.reportHost(dbOf(ctx), host, host.host, {\n protocol,\n name: input.name,\n platform: input.platform,\n agents: input.agents,\n devices: input.devices,\n presenceDue: input.presenceDue,\n online: true,\n ttlMs: 2 * deps.heartbeatMs,\n });\n learnAgents(id, input.agents);\n welcomed.add(id);\n return {\n id,\n accepted: true,\n protocol,\n leaseMs: deps.leaseMs,\n heartbeatMs: deps.heartbeatMs,\n userActivity: true,\n };\n },\n }),\n hostReport: chatAction(\"host\", enforcing, {\n description:\n \"This computer went offline, changed its agents, or looked for them again (`agentsChecked`).\",\n input: z.object({\n online: z.boolean(),\n agents: z.array(agentInfoSchema).max(32),\n devices: z.array(z.string().min(1).max(64)).max(256).optional(),\n presenceDue: presenceDueSchema.optional(),\n agentsChecked: z.literal(true).optional(),\n }),\n writes: [HOSTS_TAG],\n run: async (\n input,\n host,\n ctx,\n ): Promise<{ readonly id: string; readonly onlineUntil: number }> => {\n const db = dbOf(ctx);\n const known = await welcome(host, db);\n const { onlineUntil } = await deps.store.reportHost(db, host, host.host, {\n protocol: known.protocol,\n name: known.name,\n platform: known.platform,\n agents: input.agents,\n devices: input.devices,\n presenceDue: input.presenceDue,\n agentsCheckedAt: input.agentsChecked ? Date.now() : undefined,\n online: input.online,\n ttlMs: 2 * deps.heartbeatMs,\n });\n learnAgents(host.host.hostId, input.agents);\n return { id: host.host.hostId, onlineUntil };\n },\n }),\n hostAgentToken: chatAction(\"host\", enforcing, {\n description:\n \"A token for an agent on this computer outside any turn, such as Claude Code in a terminal, to call the app's actions as the user; revoked with the grant.\",\n input: z.object({ agent: z.string().min(1).max(120) }),\n run: async ({ agent }, host, ctx): Promise<Delegation> => {\n await requireWelcome(host, dbOf(ctx));\n if (!deps.auth.delegateAgent) {\n throw new ActionError(\n \"not_found\",\n \"This app's agents run only in its sidebar.\",\n );\n }\n return deps.auth.delegateAgent(host.host, { agent, ttlMs: AGENT_TOKEN_TTL_MS });\n },\n }),\n hostClaim: chatAction(\"host\", enforcing, {\n description:\n \"Take the next turn addressed to this computer with its turn token; not_found when none waits.\",\n input: z.object({}),\n run: async (_input, host, ctx): Promise<ClaimedTurn> => {\n const claimed = await session.claim(host, dbOf(ctx));\n if (!claimed) throw new ActionError(\"not_found\", \"No turn is waiting.\");\n return claimed;\n },\n }),\n hostSignals: chatAction(\"host\", enforcing, {\n description: \"Answers and stop requests for the turns this computer runs.\",\n input: z.object({ turns: z.array(z.object({ turnId, afterSeq })).max(16) }),\n run: async (input, host, ctx): Promise<TurnSignals[]> => {\n for (const turn of input.turns) deps.pushed?.confirm(turn.turnId);\n const db = dbOf(ctx);\n await requireWelcome(host, db);\n const signals = await deps.store.readSignals(db, host, host.host, input.turns);\n return Promise.all(\n signals.map(async (batch): Promise<TurnSignals> => {\n const answering = new Set(\n batch.items.flatMap((item) =>\n item.kind === \"answer\" && item.body.signed\n ? [item.body.signed.deviceId]\n : [],\n ),\n );\n const devices = (\n await Promise.all(\n [...answering].map((deviceId) =>\n deps.auth.device?.(host.userId, deviceId),\n ),\n )\n ).filter((device) => device !== undefined);\n return devices.length > 0 ? { ...batch, devices } : batch;\n }),\n );\n },\n }),\n hostAppend: chatAction(\"host\", enforcing, {\n description:\n \"Append finished items of a running turn and extend its lease; no items only renews it.\",\n input: z.object({ turnId, items: z.array(hostItemDraft).max(64) }),\n run: async (\n input,\n host,\n ctx,\n ): Promise<{\n readonly id: string;\n readonly leaseUntil: number;\n readonly token: ClaimedTurn[\"token\"];\n }> => {\n deps.pushed?.confirm(input.turnId);\n await requireWelcome(host, dbOf(ctx));\n const appended = await deps.transact(host, async (tx) => {\n const result = await deps.store.appendHostItems(\n tx,\n host,\n host.host,\n input.turnId,\n input.items,\n deps.leaseMs,\n );\n return {\n result,\n threadId: input.items.length > 0 ? result.threadId : undefined,\n };\n });\n const token = await mint(host, dbOf(ctx), { ...appended, turnId: input.turnId });\n return { id: appended.threadId, leaseUntil: appended.leaseUntil, token };\n },\n }),\n hostFinish: chatAction(\"host\", enforcing, {\n description: \"End a turn, once.\",\n input: z.object({\n turnId,\n outcome: z.discriminatedUnion(\"state\", [\n z.object({ state: z.literal(\"done\"), stopReason: z.string() }),\n z.object({ state: z.literal(\"cancelled\") }),\n z.object({ state: z.literal(\"failed\"), reason: z.enum(TURN_FAILURES) }),\n ]),\n }),\n run: async (input, host, ctx): Promise<{ readonly id: string }> => {\n deps.pushed?.confirm(input.turnId);\n await requireWelcome(host, dbOf(ctx));\n const finished = await deps.transact(host, async (tx) => {\n const result = await deps.store.finishTurn(\n tx,\n host,\n host.host,\n input.turnId,\n input.outcome,\n );\n return { result, threadId: result.threadId };\n });\n deps.relay.settle(host, finished.threadId, input.turnId);\n return { id: finished.threadId };\n },\n }),\n };\n}\n\n/**\n * The chat's actions at `/_parlor/chat/actions/<name>`: plugin actions, so never on MCP\n * and never callable by an agent. Writes return the thread or host id as `id`.\n */\nexport function chatActions(\n deps: ChatActionDeps,\n session: HostSession = hostSession(deps),\n) {\n return createRegistry({ ...userChatActions(deps), ...hostChatActions(deps, session) });\n}\n\nexport type ChatActionRegistry = ReturnType<typeof chatActions>;\nexport type ChatActionMap = ActionsOf<ChatActionRegistry>;\nexport type ChatUserActionMap = ReturnType<typeof userChatActions>;\nexport type ChatHostActionMap = ReturnType<typeof hostChatActions>;\n"]}
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/server/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,GAIZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAkB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAsC,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAmB,MAAM,aAAa,CAAC;AAW7E,OAAO,EAAE,aAAa,EAAoB,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,QAAQ,EACR,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CA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C,CAAC,CAAC;gBACtC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;oBACtD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CACxC,EAAE,EACF,IAAI,EACJ,IAAI,CAAC,IAAI,EACT,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,OAAO,CACd,CAAC;oBACF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;gBAC/C,CAAC,CAAC,CAAC;gBACH,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;gBAC3E,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACnC,CAAC;SACF,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,IAAoB,EACpB,OAAO,GAAgB,WAAW,CAAC,IAAI,CAAC;IAExC,OAAO,cAAc,CAAC,EAAE,GAAG,eAAe,CAAC,IAAI,CAAC,EAAE,GAAG,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;AACzF,CAAC","sourcesContent":["import {\n type ActionContext,\n ActionError,\n type HostId,\n type ThreadId,\n type TurnId,\n} from \"@parlor/core\";\nimport { type ActionsOf, createRegistry } from \"@parlor/core/registry\";\nimport { type AuthProvider, type Delegation, HOST_GRANTS_TAG } from \"@parlor/server\";\nimport { z } from \"zod\";\n\nimport { idSchema } from \"../id-schemas.js\";\nimport { chatItemBodies, hostItemDraft, type LoggedItem } from \"../items.js\";\nimport type {\n AgentInfo,\n ChatOwner,\n ChatSnapshot,\n ThreadHistory,\n ThreadList,\n ClaimedTurn,\n HostSummary,\n TurnSignals,\n} from \"../model.js\";\nimport { HOST_PROTOCOL, type HostWelcome, PUSHED_TURNS_PROTOCOL } from \"../protocol.js\";\nimport {\n CHAT_ACTIVITY_TAG,\n CHAT_AGENTS_CHECK_TAG,\n CHAT_TAG,\n HOSTS_TAG,\n} from \"../tags.js\";\nimport { turnContext } from \"./context.js\";\nimport type { LiveRelay } from \"./live.js\";\nimport { type ChatHost, chatAction } from \"./party.js\";\nimport type { TurnPush } from \"./push.js\";\nimport { agentInfoSchema, TURN_FAILURES } from \"./rows.js\";\n\nconst presenceDueSchema = z\n .record(z.string().min(1).max(64), z.number().int().nonnegative())\n .refine((due) => Object.keys(due).length <= 256, \"At most 256 devices.\");\nimport {\n type ChatDb,\n type ChatStore,\n type StoredHost,\n THREAD_LIST_LIMIT,\n} from \"./store.js\";\n\nexport { CHAT_ACTIVITY_TAG, CHAT_TAG, HOSTS_TAG, HOST_GRANTS_TAG };\n\nexport interface Written<T> {\n readonly result: T;\n readonly threadId: ThreadId | undefined;\n}\n\nexport interface ChatActionDeps {\n readonly enforcing: boolean;\n /**\n * Runs `work` in one transaction with the thread's sync event. Actions that call the auth\n * provider do so outside it, because a provider may read through another connection\n * (PGlite has one, and the transaction holds it).\n */\n /** Runs `work` in one transaction and wakes only `owner`'s tabs and computers. */\n readonly transact: <T>(\n owner: ChatOwner,\n work: (tx: ChatDb) => Promise<Written<T>>,\n ) => Promise<T>;\n /** Commits the lapsed leases and liveness of `owner`, with the sync events they owe. */\n readonly reconcile: (owner: ChatOwner) => Promise<void>;\n /** Drops the owner's computer rows whose grant is gone; best effort, never fails a read. */\n readonly pruneHosts: (owner: ChatOwner, hostIds: readonly HostId[]) => Promise<void>;\n readonly auth: AuthProvider;\n readonly store: ChatStore;\n readonly relay: LiveRelay;\n readonly leaseMs: number;\n readonly heartbeatMs: number;\n readonly maxQueued: number;\n readonly instructions: string | undefined;\n readonly appName: string;\n readonly appOrigin: () => string;\n /** Hands a queued turn straight to its computer; without it computers only claim. */\n readonly pushed?: TurnPush | undefined;\n}\n\nconst threadId = idSchema(\"thread\");\nconst turnId = idSchema(\"turn\");\nconst itemId = idSchema(\"item\");\nconst afterSeq = z.number().int().min(0);\n\nconst MIN_HOST_PROTOCOL = 2;\nconst CONTEXT_HISTORY_ITEMS = 200;\n/** An agent outside a turn asks again well inside the revocation horizon. */\nconst AGENT_TOKEN_TTL_MS = 10 * 60_000;\nconst TERMINAL: ReadonlySet<string> = new Set([\"done\", \"failed\", \"cancelled\"]);\n\nconst dbOf = (ctx: ActionContext) => ctx.db as ChatDb;\n\nasync function activeHosts(\n deps: ChatActionDeps,\n db: ChatDb,\n owner: ChatOwner,\n): Promise<StoredHost[]> {\n const hosts = await deps.store.listHosts(db, owner);\n const { hostActive } = deps.auth;\n if (!hostActive) return hosts;\n const holding = await Promise.all(\n hosts.map((host) => hostActive.call(deps.auth, host.grantId)),\n );\n const gone = hosts.filter((_host, at) => !holding[at]);\n if (gone.length > 0) {\n await deps.pruneHosts(\n owner,\n gone.map((host) => host.id),\n );\n }\n return hosts.filter((_host, at) => holding[at]);\n}\n\nconst summaryOf = ({\n grantId: _grantId,\n protocol: _protocol,\n ...summary\n}: StoredHost): HostSummary => summary;\n\nexport function userChatActions(deps: ChatActionDeps) {\n const { enforcing } = deps;\n return {\n open: chatAction(\"user\", enforcing, {\n description:\n \"The sidebar's first paint in one round trip: threads, computers, and a thread's last page with what streams now.\",\n input: z.object({\n threadId: threadId.optional(),\n limit: z.number().int().min(1).max(500).default(200),\n }),\n reads: (input) => [\n [CHAT_TAG, ...(input.threadId ? [input.threadId] : [])],\n [HOSTS_TAG],\n [HOST_GRANTS_TAG],\n ],\n run: async (input, user, ctx): Promise<ChatSnapshot> => {\n const db = dbOf(ctx);\n const [threads, hosts, page] = await Promise.all([\n deps.store.listThreads(db, user),\n activeHosts(deps, db, user),\n deps.store.readPage(db, user, input.threadId, input.limit),\n ]);\n const thread = page.thread;\n const open = thread ? deps.relay.open(user, thread.id) : [];\n const streaming = open.filter((turn) => {\n const state = page.turns.find((status) => status.turnId === turn.turnId)?.state;\n const ended = state !== undefined && TERMINAL.has(state);\n if (ended) deps.relay.settle(user, turn.threadId, turn.turnId);\n return !ended;\n });\n return {\n threads,\n ...(threads.length >= THREAD_LIST_LIMIT ? { moreThreads: true } : {}),\n hosts: hosts.map(summaryOf),\n page: { ...page, open: streaming },\n };\n },\n }),\n items: chatAction(\"user\", enforcing, {\n description: \"A thread's items after a sequence number.\",\n input: z.object({ threadId, afterSeq }),\n reads: (input) => [[CHAT_TAG, input.threadId]],\n run: (input, user, ctx): Promise<LoggedItem[]> =>\n deps.store.readItemsAfter(dbOf(ctx), user, input.threadId, input.afterSeq),\n }),\n history: chatAction(\"user\", enforcing, {\n description:\n \"A thread's items before a sequence number, oldest first, with their turns; hasMore while older ones remain.\",\n input: z.object({\n threadId,\n beforeSeq: z.number().int().min(1),\n limit: z.number().int().min(1).max(500).default(200),\n }),\n reads: (input) => [[CHAT_TAG, input.threadId]],\n run: async (input, user, ctx): Promise<ThreadHistory> => {\n const read = deps.store.readItemsBefore?.bind(deps.store);\n if (!read)\n throw new ActionError(\"not_found\", \"This chat store keeps no history.\");\n return read(dbOf(ctx), user, input.threadId, input.beforeSeq, input.limit);\n },\n }),\n threadsBefore: chatAction(\"user\", enforcing, {\n description:\n \"The user's threads updated before a thread, newest first, for the list past what open returned.\",\n input: z.object({\n before: z.object({ updatedAt: z.number().int().min(0), id: threadId }),\n limit: z.number().int().min(1).max(500).default(200),\n }),\n reads: [CHAT_TAG],\n run: async (input, user, ctx): Promise<ThreadList> => {\n const list = deps.store.listThreadsBefore?.bind(deps.store);\n if (!list)\n throw new ActionError(\"not_found\", \"This chat store keeps no history.\");\n return list(dbOf(ctx), user, input.before, input.limit);\n },\n }),\n hosts: chatAction(\"user\", enforcing, {\n description: \"The user's computers and the agents on them.\",\n input: z.object({}),\n reads: [HOSTS_TAG, HOST_GRANTS_TAG],\n run: async (_input, user, ctx): Promise<HostSummary[]> =>\n (await activeHosts(deps, dbOf(ctx), user)).map(summaryOf),\n }),\n send: chatAction(\"user\", enforcing, {\n description: \"Send a prompt to an agent on one of the user's computers.\",\n input: z.object({\n threadId,\n turnId,\n itemId,\n clientId: z.string().min(1).max(128),\n prompt: chatItemBodies.prompt.body,\n }),\n run: async (\n input,\n user,\n ctx,\n ): Promise<{ readonly id: string; readonly turnId: string }> => {\n const hosts = await activeHosts(deps, dbOf(ctx), user);\n const host = hosts.find(\n (candidate) => candidate.id === input.prompt.agent.hostId,\n );\n if (!host) throw new ActionError(\"not_found\", \"Computer not found\");\n const sent = await deps.transact(user, async (tx) => {\n await deps.store.appendUserItems(tx, user, {\n threadId: input.threadId,\n turnId: input.turnId,\n items: [{ id: input.itemId, kind: \"prompt\", body: input.prompt }],\n turn: {\n turnId: input.turnId,\n agent: input.prompt.agent,\n clientId: input.clientId,\n deviceId: user.deviceId,\n maxQueued: deps.maxQueued,\n },\n });\n return {\n result: { id: input.threadId, turnId: input.turnId },\n threadId: input.threadId,\n };\n });\n if (host.protocol >= PUSHED_TURNS_PROTOCOL) deps.pushed?.offer(user, host.id);\n return sent;\n },\n }),\n answer: chatAction(\"user\", enforcing, {\n description: \"Answer the agent's permission prompt or question.\",\n input: z.object({ threadId, turnId, itemId, answer: chatItemBodies.answer.body }),\n run: async (input, user): Promise<{ readonly id: string }> => {\n const { signed } = input.answer;\n if (signed && deps.auth.device) {\n const device = await deps.auth.device(user.userId, signed.deviceId);\n if (!device) {\n throw new ActionError(\"forbidden\", \"This device cannot answer.\");\n }\n }\n return deps.transact(user, async (tx) => {\n await deps.store.appendUserItems(tx, user, {\n threadId: input.threadId,\n turnId: input.turnId,\n items: [{ id: input.itemId, kind: \"answer\", body: input.answer }],\n });\n return { result: { id: input.threadId }, threadId: input.threadId };\n });\n },\n }),\n cancel: chatAction(\"user\", enforcing, {\n description: \"Stop the running turn; what the agent already said is kept.\",\n input: z.object({ threadId, turnId, itemId }),\n writes: [CHAT_TAG],\n run: async (input, user, ctx): Promise<{ readonly id: string }> => {\n await deps.store.appendUserItems(dbOf(ctx), user, {\n threadId: input.threadId,\n turnId: input.turnId,\n items: [{ id: input.itemId, kind: \"cancel\", body: {} }],\n });\n return { id: input.threadId };\n },\n }),\n userActive: chatAction(\"user\", enforcing, {\n description:\n \"Tell the user's computers a tab is in use, so a polling computer speeds up; carries no content and writes no table.\",\n input: z.object({}),\n writes: [CHAT_ACTIVITY_TAG],\n run: (): { readonly ok: true } => ({ ok: true }),\n }),\n checkAgents: chatAction(\"user\", enforcing, {\n description:\n \"Ask the user's computers to look again for the coding agents installed on them; each reports what it found, stamped `agentsCheckedAt`. Answers when it asked, by the same clock.\",\n input: z.object({}),\n writes: [CHAT_AGENTS_CHECK_TAG],\n run: (): { readonly askedAt: number } => ({ askedAt: Date.now() }),\n }),\n };\n}\n\n/**\n * What the server keeps about the computers it serves: which said hello, their agents'\n * names, and how a turn is claimed for one, by `hostClaim` or pushed to it.\n */\nexport function hostSession(deps: ChatActionDeps) {\n const welcomed = new Set<HostId>();\n const welcome = async (host: ChatHost, db: ChatDb) => {\n const hosts = await deps.store.listHosts(db, host);\n const known = hosts.find((candidate) => candidate.id === host.host.hostId);\n if (!known) throw new ActionError(\"forbidden\", \"Say hello before anything else.\");\n if (known.protocol < MIN_HOST_PROTOCOL) {\n await deps.pruneHosts(host, [known.id]);\n throw new ActionError(\"forbidden\", \"Say hello before anything else.\");\n }\n welcomed.add(known.id);\n return known;\n };\n const requireWelcome = async (host: ChatHost, db: ChatDb) => {\n if (!welcomed.has(host.host.hostId)) await welcome(host, db);\n };\n const agentNames = new Map<HostId, ReadonlyMap<string, string>>();\n const learnAgents = (hostId: HostId, agents: readonly AgentInfo[]) => {\n agentNames.set(hostId, new Map(agents.map((agent) => [agent.id, agent.name])));\n };\n const agentNameOf = async (host: ChatHost, db: ChatDb, agentId: string) => {\n if (!agentNames.has(host.host.hostId)) {\n const known = (await deps.store.listHosts(db, host)).find(\n (candidate) => candidate.id === host.host.hostId,\n );\n if (known) learnAgents(known.id, known.agents);\n }\n return agentNames.get(host.host.hostId)?.get(agentId) ?? agentId;\n };\n const mint = async (\n host: ChatHost,\n db: ChatDb,\n turn: {\n threadId: ThreadId;\n turnId: TurnId;\n clientId: string;\n agentId: string;\n scope: string;\n },\n ) => {\n if (!deps.auth.delegate) {\n throw new ActionError(\"internal\", \"The auth provider cannot mint turn tokens.\");\n }\n return deps.auth.delegate(host.host, {\n threadId: turn.threadId,\n turnId: turn.turnId,\n clientId: turn.clientId,\n agent: await agentNameOf(host, db, turn.agentId),\n ttlMs: deps.leaseMs,\n scope: turn.scope,\n });\n };\n /** The next turn waiting for `host`, claimed for it with its token and context; undefined when none waits. */\n const claim = async (host: ChatHost, db: ChatDb): Promise<ClaimedTurn | undefined> => {\n await requireWelcome(host, db);\n await deps.reconcile(host);\n const stored = await deps.transact(host, async (tx) => {\n const taken = await deps.store.claimTurn(tx, host, host.host, deps.leaseMs);\n return { result: taken, threadId: taken?.id };\n });\n if (!stored) return undefined;\n const { owner = host, ...claimed } = stored;\n try {\n const deviceId = claimed.prompt.body.signed?.deviceId;\n const [token, device, account, page] = await Promise.all([\n mint(host, db, {\n threadId: claimed.id,\n turnId: claimed.turnId,\n clientId: claimed.clientId,\n agentId: claimed.agent.agentId,\n scope: owner.scope,\n }),\n deviceId ? deps.auth.device?.(host.userId, deviceId) : undefined,\n deps.auth.account?.(host.userId),\n deps.store.readPage(db, owner, claimed.id, CONTEXT_HISTORY_ITEMS),\n ]);\n const context = turnContext({\n appName: deps.appName,\n appOrigin: deps.appOrigin(),\n account,\n device,\n instructions: deps.instructions,\n history: page.items.filter((item) => item.seq < claimed.prompt.seq),\n });\n return { ...claimed, device, context, token };\n } catch (error) {\n await release(host, claimed.id, claimed.turnId).catch(() => false);\n throw error;\n }\n };\n /** Puts a claimed turn back in the queue, waking the computer to claim it again. */\n const release = (host: ChatHost, thread: ThreadId, turn: TurnId) =>\n deps.transact(host, async (tx) => {\n const released = await deps.store.releaseClaim(tx, host, host.host, turn);\n return { result: released, threadId: thread };\n });\n return {\n welcome,\n requireWelcome,\n learnAgents,\n agentNameOf,\n mint,\n claim,\n release,\n welcomed,\n };\n}\n\nexport type HostSession = ReturnType<typeof hostSession>;\n\n/** What the user's computers call; `hostHello` first on every link. */\nexport function hostChatActions(\n deps: ChatActionDeps,\n session: HostSession = hostSession(deps),\n) {\n const { enforcing } = deps;\n const { welcome, requireWelcome, learnAgents, mint, welcomed } = session;\n return {\n hostHello: chatAction(\"host\", enforcing, {\n description:\n \"A link's first call: agree on the host protocol and report this computer online with its agents.\",\n input: z.object({\n protocols: z.object({\n min: z.number().int().min(1),\n max: z.number().int().min(1),\n }),\n hostVersion: z.string().min(1).max(32),\n name: z.string().min(1).max(80),\n platform: z.string().min(1).max(32),\n agents: z.array(agentInfoSchema).max(32),\n devices: z.array(z.string().min(1).max(64)).max(256).optional(),\n presenceDue: presenceDueSchema.optional(),\n }),\n writes: [HOSTS_TAG],\n run: async (input, host, ctx): Promise<HostWelcome & { readonly id: string }> => {\n const id = host.host.hostId;\n const protocols = { min: MIN_HOST_PROTOCOL, max: HOST_PROTOCOL };\n const refuse = async (reason: \"host_too_old\" | \"app_too_old\") => {\n welcomed.delete(id);\n await deps.store.pruneHosts(dbOf(ctx), host, [id]);\n return { id, accepted: false as const, reason, protocols };\n };\n if (input.protocols.max < protocols.min) return refuse(\"host_too_old\");\n const protocol = Math.min(input.protocols.max, protocols.max);\n if (protocol < input.protocols.min) return refuse(\"app_too_old\");\n await deps.store.reportHost(dbOf(ctx), host, host.host, {\n protocol,\n name: input.name,\n platform: input.platform,\n agents: input.agents,\n devices: input.devices,\n presenceDue: input.presenceDue,\n online: true,\n ttlMs: 2 * deps.heartbeatMs,\n });\n learnAgents(id, input.agents);\n welcomed.add(id);\n return {\n id,\n accepted: true,\n protocol,\n leaseMs: deps.leaseMs,\n heartbeatMs: deps.heartbeatMs,\n userActivity: true,\n };\n },\n }),\n hostReport: chatAction(\"host\", enforcing, {\n description:\n \"This computer went offline, changed its agents, or looked for them again (`agentsChecked`).\",\n input: z.object({\n online: z.boolean(),\n agents: z.array(agentInfoSchema).max(32),\n devices: z.array(z.string().min(1).max(64)).max(256).optional(),\n presenceDue: presenceDueSchema.optional(),\n agentsChecked: z.literal(true).optional(),\n }),\n writes: [HOSTS_TAG],\n run: async (\n input,\n host,\n ctx,\n ): Promise<{ readonly id: string; readonly onlineUntil: number }> => {\n const db = dbOf(ctx);\n const known = await welcome(host, db);\n const { onlineUntil } = await deps.store.reportHost(db, host, host.host, {\n protocol: known.protocol,\n name: known.name,\n platform: known.platform,\n agents: input.agents,\n devices: input.devices,\n presenceDue: input.presenceDue,\n agentsCheckedAt: input.agentsChecked ? Date.now() : undefined,\n online: input.online,\n ttlMs: 2 * deps.heartbeatMs,\n });\n learnAgents(host.host.hostId, input.agents);\n return { id: host.host.hostId, onlineUntil };\n },\n }),\n hostAgentToken: chatAction(\"host\", enforcing, {\n description:\n \"A token for an agent on this computer outside any turn, such as Claude Code in a terminal, to call the app's actions as the user; revoked with the grant.\",\n input: z.object({ agent: z.string().min(1).max(120) }),\n run: async ({ agent }, host, ctx): Promise<Delegation> => {\n await requireWelcome(host, dbOf(ctx));\n if (!deps.auth.delegateAgent) {\n throw new ActionError(\n \"not_found\",\n \"This app's agents run only in its sidebar.\",\n );\n }\n return deps.auth.delegateAgent(host.host, { agent, ttlMs: AGENT_TOKEN_TTL_MS });\n },\n }),\n hostClaim: chatAction(\"host\", enforcing, {\n description:\n \"Take the next turn addressed to this computer with its turn token; not_found when none waits.\",\n input: z.object({}),\n run: async (_input, host, ctx): Promise<ClaimedTurn> => {\n const claimed = await session.claim(host, dbOf(ctx));\n if (!claimed) throw new ActionError(\"not_found\", \"No turn is waiting.\");\n return claimed;\n },\n }),\n hostSignals: chatAction(\"host\", enforcing, {\n description: \"Answers and stop requests for the turns this computer runs.\",\n input: z.object({ turns: z.array(z.object({ turnId, afterSeq })).max(16) }),\n run: async (input, host, ctx): Promise<TurnSignals[]> => {\n for (const turn of input.turns) deps.pushed?.confirm(turn.turnId);\n const db = dbOf(ctx);\n await requireWelcome(host, db);\n const signals = await deps.store.readSignals(db, host, host.host, input.turns);\n return Promise.all(\n signals.map(async (batch): Promise<TurnSignals> => {\n const answering = new Set(\n batch.items.flatMap((item) =>\n item.kind === \"answer\" && item.body.signed\n ? [item.body.signed.deviceId]\n : [],\n ),\n );\n const devices = (\n await Promise.all(\n [...answering].map((deviceId) =>\n deps.auth.device?.(host.userId, deviceId),\n ),\n )\n ).filter((device) => device !== undefined);\n return devices.length > 0 ? { ...batch, devices } : batch;\n }),\n );\n },\n }),\n hostAppend: chatAction(\"host\", enforcing, {\n description:\n \"Append finished items of a running turn and extend its lease; no items only renews it.\",\n input: z.object({ turnId, items: z.array(hostItemDraft).max(64) }),\n run: async (\n input,\n host,\n ctx,\n ): Promise<{\n readonly id: string;\n readonly leaseUntil: number;\n readonly token: ClaimedTurn[\"token\"];\n }> => {\n deps.pushed?.confirm(input.turnId);\n await requireWelcome(host, dbOf(ctx));\n const appended = await deps.transact(host, async (tx) => {\n const result = await deps.store.appendHostItems(\n tx,\n host,\n host.host,\n input.turnId,\n input.items,\n deps.leaseMs,\n );\n return {\n result,\n threadId: input.items.length > 0 ? result.threadId : undefined,\n };\n });\n const token = await mint(host, dbOf(ctx), {\n ...appended,\n turnId: input.turnId,\n scope: (appended.owner ?? host).scope,\n });\n return { id: appended.threadId, leaseUntil: appended.leaseUntil, token };\n },\n }),\n hostFinish: chatAction(\"host\", enforcing, {\n description: \"End a turn, once.\",\n input: z.object({\n turnId,\n outcome: z.discriminatedUnion(\"state\", [\n z.object({ state: z.literal(\"done\"), stopReason: z.string() }),\n z.object({ state: z.literal(\"cancelled\") }),\n z.object({ state: z.literal(\"failed\"), reason: z.enum(TURN_FAILURES) }),\n ]),\n }),\n run: async (input, host, ctx): Promise<{ readonly id: string }> => {\n deps.pushed?.confirm(input.turnId);\n await requireWelcome(host, dbOf(ctx));\n const finished = await deps.transact(host, async (tx) => {\n const result = await deps.store.finishTurn(\n tx,\n host,\n host.host,\n input.turnId,\n input.outcome,\n );\n return { result, threadId: result.threadId };\n });\n deps.relay.settle(finished.owner ?? host, finished.threadId, input.turnId);\n return { id: finished.threadId };\n },\n }),\n };\n}\n\n/**\n * The chat's actions at `/_parlor/chat/actions/<name>`: plugin actions, so never on MCP\n * and never callable by an agent. Writes return the thread or host id as `id`.\n */\nexport function chatActions(\n deps: ChatActionDeps,\n session: HostSession = hostSession(deps),\n) {\n return createRegistry({ ...userChatActions(deps), ...hostChatActions(deps, session) });\n}\n\nexport type ChatActionRegistry = ReturnType<typeof chatActions>;\nexport type ChatActionMap = ActionsOf<ChatActionRegistry>;\nexport type ChatUserActionMap = ReturnType<typeof userChatActions>;\nexport type ChatHostActionMap = ReturnType<typeof hostChatActions>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,SAAS,EAEd,KAAK,MAAM,EAEZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAW1E,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAM3D,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,WAAW,EACX,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,eAAe,EACf,eAAe,EACf,SAAS,EACT,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,uBAAuB,EACvB,WAAW,EACX,KAAK,gBAAgB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EACL,cAA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M,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,mGAAmG;IACnG,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,SAAS,CAAC,GAAG,SAAS,CAAC;CAChD;AAED,oFAAoF;AACpF,eAAO,MAAM,YAAY,QAAwB,CAAC;AASlD;;;GAGG;AACH,wBAAgB,IAAI,CAAC,OAAO,GAAE,WAAgB,GAAG,YAAY,CAoH5D"}
|
package/dist/server/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { userAudience } from "@parlor/agent-ui/server";
|
|
1
|
+
import { accountAudience, userAudience } from "@parlor/agent-ui/server";
|
|
2
2
|
import { DEV_USER_ID, userOf, } from "@parlor/core";
|
|
3
3
|
import { REVOCATION_HORIZON_MS } from "@parlor/server";
|
|
4
4
|
import { CHAT_PLUGIN } from "../protocol.js";
|
|
@@ -58,7 +58,7 @@ export function chat(options = {}) {
|
|
|
58
58
|
}
|
|
59
59
|
const relay = (options.relay ?? inProcessRelay)();
|
|
60
60
|
const db = () => database.read();
|
|
61
|
-
const ownStream = (owner) => userAudience(owner.scope, owner.userId);
|
|
61
|
+
const ownStream = (owner) => accountAudience(owner.userId) ?? userAudience(owner.scope, owner.userId);
|
|
62
62
|
const transact = (owner, work) => database.transaction(async (tx) => {
|
|
63
63
|
const { result, threadId } = await work(tx);
|
|
64
64
|
if (threadId !== undefined)
|