@parlor/core 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/action.d.ts +11 -0
- package/dist/action.d.ts.map +1 -1
- package/dist/action.js.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/ids.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/principal.js.map +1 -1
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/invoke.js.map +1 -1
- package/dist/registry/registry.js.map +1 -1
- package/dist/shell-origins.js.map +1 -1
- package/dist/tags.js.map +1 -1
- package/package.json +1 -1
package/dist/action.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ export interface ListenOptions {
|
|
|
16
16
|
readonly onLost?: (() => void) | undefined;
|
|
17
17
|
}
|
|
18
18
|
export interface DataProvider<TDb = unknown> {
|
|
19
|
+
/**
|
|
20
|
+
* Work deferred to the server's first request, such as migrations on runtimes that allow
|
|
21
|
+
* no I/O while the app loads. The server awaits it before anything else touches the data.
|
|
22
|
+
*/
|
|
23
|
+
prepare?(): Promise<void>;
|
|
19
24
|
read(): TDb;
|
|
20
25
|
transaction<T>(run: (tx: TDb) => Promise<T>): Promise<T>;
|
|
21
26
|
listen?(channel: string, handler: (payload: string) => void, options?: ListenOptions): Promise<Unlisten>;
|
|
@@ -27,6 +32,12 @@ export interface ActionContext {
|
|
|
27
32
|
readonly principal: Principal;
|
|
28
33
|
readonly db: ParlorDatabase;
|
|
29
34
|
readonly signal?: AbortSignal | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* The HTTP request that made the call, whichever surface it came through; undefined for
|
|
37
|
+
* an in-process call. For what the request carries besides identity, such as a cookie
|
|
38
|
+
* the app set; who is calling is `principal`.
|
|
39
|
+
*/
|
|
40
|
+
readonly request?: Request | undefined;
|
|
30
41
|
}
|
|
31
42
|
export interface TableLike {
|
|
32
43
|
readonly _: {
|
package/dist/action.d.ts.map
CHANGED
|
@@ -1 +1 @@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gBAAgB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AACpE,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,gBAAgB,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
|
package/dist/action.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action.js","sourceRoot":"","sources":["../src/action.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"action.js","sourceRoot":"","sources":["../src/action.ts"],"names":[],"mappings":"AAuFA,MAAM,OAAO,GAAkB,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAYvD,MAAM,UAAU,YAAY,CAC1B,MAAqC;IAErC,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAiB;IAC1C,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,iBAAiB,GAA8B,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAE/E,MAAM,UAAU,iBAAiB,CAAC,MAAiB,EAAE,MAAoB;IACvE,OAAO,MAAM,CAAC,OAAO,KAAK,IAAI,IAAI,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,cAAc,GAAG;IACrB,SAAS,EAAE,MAAM;IACjB,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,MAAM;CAC0C,CAAC;AAEzD,MAAM,UAAU,iBAAiB,CAAC,SAAoB;IACpD,IAAI,SAAS,CAAC,IAAI,KAAK,OAAO,IAAI,SAAS,CAAC,IAAI;QAAE,OAAO,OAAO,CAAC;IACjE,OAAO,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAiB,EAAE,SAAkB;IAClE,OAAO,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI,CAAC;AAC7C,CAAC","sourcesContent":["import type { z } from \"zod\";\n\nimport type { Principal, PrincipalKind } from \"./principal.js\";\n\nexport type ActionSource = \"ui\" | \"agent\" | \"http\" | \"mcp\";\n\nexport interface DataRegister {}\n\nexport type ParlorDatabase = DataRegister extends { database: infer D } ? D : unknown;\n\nexport type Unlisten = () => Promise<void>;\n\nexport interface ListenOptions {\n /**\n * The connection behind this listener dropped. It is gone for good, and notifications\n * sent until a new `listen` call succeeds are lost, so a listener must listen again and\n * reload whatever it derived from them.\n */\n readonly onLost?: (() => void) | undefined;\n}\n\nexport interface DataProvider<TDb = unknown> {\n /**\n * Work deferred to the server's first request, such as migrations on runtimes that allow\n * no I/O while the app loads. The server awaits it before anything else touches the data.\n */\n prepare?(): Promise<void>;\n read(): TDb;\n transaction<T>(run: (tx: TDb) => Promise<T>): Promise<T>;\n listen?(\n channel: string,\n handler: (payload: string) => void,\n options?: ListenOptions,\n ): Promise<Unlisten>;\n close?(): Promise<void>;\n}\n\nexport interface ActionContext {\n readonly scope: string;\n readonly source: ActionSource;\n readonly principal: Principal;\n readonly db: ParlorDatabase;\n readonly signal?: AbortSignal | undefined;\n /**\n * The HTTP request that made the call, whichever surface it came through; undefined for\n * an in-process call. For what the request carries besides identity, such as a cookie\n * the app set; who is calling is `principal`.\n */\n readonly request?: Request | undefined;\n}\n\nexport interface TableLike {\n readonly _: { readonly name: string };\n}\n\nexport type TagSource = string | TableLike;\nexport type Tag = readonly (string | number)[];\nexport type ReadTags<TInput> = readonly TagSource[] | ((input: TInput) => readonly Tag[]);\n\nexport interface ActionConfig<TInput extends z.ZodType, TOutput> {\n readonly description: string;\n readonly input: TInput;\n readonly reads?: ReadTags<z.output<TInput>> | undefined;\n readonly writes?: readonly TagSource[] | undefined;\n /**\n * Whose clients its `writes` wake: everyone in the scope (the default), or only the\n * caller's own user, with their tabs and computers, when the scope is shared.\n */\n readonly notifies?: \"scope\" | \"user\" | undefined;\n /**\n * Ask the user to approve each call from an agent (source `mcp` or `agent`) in the app\n * before it runs. Calls from the app's own UI and plain HTTP never ask. With an enforcing\n * auth provider the source comes from the caller's credential, so this is a boundary;\n * without one it stays a UX guard over a self-declared header.\n */\n readonly confirm?: boolean | undefined;\n /**\n * Callable without signing in. Only read when the server has an enforcing auth provider,\n * which otherwise answers an anonymous caller with `unauthenticated`.\n */\n readonly public?: boolean | undefined;\n readonly run: (\n input: z.output<TInput>,\n ctx: ActionContext,\n ) => Promise<TOutput> | TOutput;\n}\n\nconst kAction: unique symbol = Symbol.for(\"fw.action\");\n\nexport interface ActionDefinition<\n TInput extends z.ZodType = z.ZodType,\n TOutput = unknown,\n> extends ActionConfig<TInput, TOutput> {\n readonly [kAction]: true;\n}\n\nexport type AnyAction = ActionDefinition<z.ZodType, unknown>;\nexport type ActionMap = Record<string, AnyAction>;\n\nexport function defineAction<TInput extends z.ZodType, TOutput>(\n config: ActionConfig<TInput, TOutput>,\n): ActionDefinition<TInput, TOutput> {\n return { ...config, [kAction]: true };\n}\n\nexport function isAction(value: unknown): value is AnyAction {\n return typeof value === \"object\" && value !== null && kAction in value;\n}\n\nexport function isMutating(action: AnyAction): boolean {\n return (action.writes?.length ?? 0) > 0;\n}\n\nconst CONFIRMED_SOURCES: ReadonlySet<ActionSource> = new Set([\"mcp\", \"agent\"]);\n\nexport function needsConfirmation(action: AnyAction, source: ActionSource): boolean {\n return action.confirm === true && CONFIRMED_SOURCES.has(source);\n}\n\nconst SOURCE_BY_KIND = {\n anonymous: \"http\",\n user: \"ui\",\n agent: \"mcp\",\n host: \"http\",\n} as const satisfies Record<PrincipalKind, ActionSource>;\n\nexport function sourceOfPrincipal(principal: Principal): ActionSource {\n if (principal.kind === \"agent\" && principal.turn) return \"agent\";\n return SOURCE_BY_KIND[principal.kind];\n}\n\nexport function needsPrincipal(action: AnyAction, enforcing: boolean): boolean {\n return enforcing && action.public !== true;\n}\n\nexport type ActionInput<A> =\n A extends ActionDefinition<infer I, unknown> ? z.input<I> : never;\nexport type ActionOutput<A> = A extends ActionDefinition<z.ZodType, infer O> ? O : never;\n"]}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,WAAW;IACX,eAAe;IACf,UAAU;IACV,sBAAsB;IACtB,0BAA0B;IAC1B,iBAAiB;IACjB,WAAW;IACX,UAAU;CACF,CAAC;AAYX,MAAM,OAAO,WAAY,SAAQ,KAAK;IAClB,IAAI,GAAG,aAAa,CAAC;IAC9B,IAAI,CAAkB;IACtB,MAAM,CAA0C;IAEzD,YACE,IAAqB,EACrB,OAAe,EACf,OAA+E;QAE/E,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QACpF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;IAChC,CAAC;IAED,MAAM;QACJ,OAAO;YACL,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC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IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC;IAChC,CAAC;IAED,MAAM;QACJ,OAAO;YACL,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAChD;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAAqB;QACnC,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE;YAC1D,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;SAC1B,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,KAAc;QAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,OAAO,IAAI,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACrF,MAAM,KAAK,GAAI,KAA4B,CAAC,KAAK,CAAC;QAClD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK,CACrF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { z } from \"zod\";\n\nexport const ACTION_ERROR_CODES = [\n \"not_found\",\n \"invalid_input\",\n \"declined\",\n \"confirmation_timeout\",\n \"confirmation_unavailable\",\n \"unauthenticated\",\n \"forbidden\",\n \"internal\",\n] as const;\n\nexport type ActionErrorCode = (typeof ACTION_ERROR_CODES)[number];\n\nexport interface ActionErrorBody {\n readonly error: {\n readonly code: ActionErrorCode;\n readonly message: string;\n readonly issues?: readonly z.core.$ZodIssue[] | undefined;\n };\n}\n\nexport class ActionError extends Error {\n override readonly name = \"ActionError\";\n readonly code: ActionErrorCode;\n readonly issues: readonly z.core.$ZodIssue[] | undefined;\n\n constructor(\n code: ActionErrorCode,\n message: string,\n options?: { issues?: readonly z.core.$ZodIssue[] | undefined; cause?: unknown },\n ) {\n super(message, options?.cause === undefined ? undefined : { cause: options.cause });\n this.code = code;\n this.issues = options?.issues;\n }\n\n toBody(): ActionErrorBody {\n return {\n error: {\n code: this.code,\n message: this.message,\n ...(this.issues ? { issues: this.issues } : {}),\n },\n };\n }\n\n static fromBody(body: ActionErrorBody): ActionError {\n return new ActionError(body.error.code, body.error.message, {\n issues: body.error.issues,\n });\n }\n\n static isBody(value: unknown): value is ActionErrorBody {\n if (typeof value !== \"object\" || value === null || !(\"error\" in value)) return false;\n const error = (value as { error: unknown }).error;\n return (\n typeof error === \"object\" && error !== null && \"code\" in error && \"message\" in error\n );\n }\n}\n"]}
|
package/dist/ids.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAmB,KAAQ,EAAE,KAAa;IAC5D,OAAO,KAAc,CAAC;AACxB,CAAC"}
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAmB,KAAQ,EAAE,KAAa;IAC5D,OAAO,KAAc,CAAC;AACxB,CAAC","sourcesContent":["declare const idKind: unique symbol;\n\nexport type IdKind = \"user\" | \"device\" | \"grant\" | \"host\" | \"thread\" | \"turn\" | \"item\";\n\nexport type Id<K extends IdKind> = string & { readonly [idKind]: K };\n\nexport type UserId = Id<\"user\">;\nexport type DeviceId = Id<\"device\">;\nexport type GrantId = Id<\"grant\">;\nexport type HostId = Id<\"host\">;\nexport type ThreadId = Id<\"thread\">;\nexport type TurnId = Id<\"turn\">;\nexport type ItemId = Id<\"item\">;\n\n/**\n * Names a string as an id. Only boundary code calls it: a verified token's claims, a\n * database row, a request body after validation.\n */\nexport function asId<K extends IdKind>(_kind: K, value: string): Id<K> {\n return value as Id<K>;\n}\n"]}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,YAAY,EACZ,QAAQ,EACR,UAAU,EAEV,iBAAiB,EACjB,cAAc,EAGd,iBAAiB,GAIlB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,WAAW,GAGZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,IAAI,GAUL,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,SAAS,EAKT,WAAW,EAEX,eAAe,EAKf,MAAM,GACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,YAAY,EACZ,QAAQ,EACR,UAAU,EAEV,iBAAiB,EACjB,cAAc,EAGd,iBAAiB,GAIlB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,WAAW,GAGZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,IAAI,GAUL,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,SAAS,EAKT,WAAW,EAEX,eAAe,EAKf,MAAM,GACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export {\n type ActionConfig,\n type ActionContext,\n type ActionDefinition,\n type ActionInput,\n type ActionMap,\n type ActionOutput,\n type ActionSource,\n type AnyAction,\n type DataProvider,\n type DataRegister,\n type Unlisten,\n defineAction,\n isAction,\n isMutating,\n type ListenOptions,\n needsConfirmation,\n needsPrincipal,\n type ParlorDatabase,\n type ReadTags,\n sourceOfPrincipal,\n type TableLike,\n type Tag,\n type TagSource,\n} from \"./action.js\";\nexport {\n ACTION_ERROR_CODES,\n ActionError,\n type ActionErrorBody,\n type ActionErrorCode,\n} from \"./errors.js\";\nexport {\n asId,\n type DeviceId,\n type GrantId,\n type HostId,\n type Id,\n type IdKind,\n type ItemId,\n type ThreadId,\n type TurnId,\n type UserId,\n} from \"./ids.js\";\nexport {\n ANONYMOUS,\n type AgentIdentity,\n type AgentPrincipal,\n type AnonymousPrincipal,\n type AuthenticatedPrincipal,\n DEV_USER_ID,\n type HostPrincipal,\n isAuthenticated,\n type Principal,\n type PrincipalKind,\n type TurnBinding,\n type UserPrincipal,\n userOf,\n} from \"./principal.js\";\nexport { SHELL_ORIGINS } from \"./shell-origins.js\";\nexport { readTagsFor, tableName, tagsOverlap, writeTagsFor } from \"./tags.js\";\n"]}
|
package/dist/principal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principal.js","sourceRoot":"","sources":["../src/principal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,GAOL,MAAM,UAAU,CAAC;AA8DlB,MAAM,CAAC,MAAM,SAAS,GAAuB,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AAEnE;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAW,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE3D,MAAM,UAAU,eAAe,CAC7B,SAAoB;IAEpB,OAAO,SAAS,CAAC,IAAI,KAAK,WAAW,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,SAAgC;IACrD,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC9C,OAAO,SAAS,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC;AACvE,CAAC"}
|
|
1
|
+
{"version":3,"file":"principal.js","sourceRoot":"","sources":["../src/principal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,GAOL,MAAM,UAAU,CAAC;AA8DlB,MAAM,CAAC,MAAM,SAAS,GAAuB,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AAEnE;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAW,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE3D,MAAM,UAAU,eAAe,CAC7B,SAAoB;IAEpB,OAAO,SAAS,CAAC,IAAI,KAAK,WAAW,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,SAAgC;IACrD,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC9C,OAAO,SAAS,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC;AACvE,CAAC","sourcesContent":["import {\n asId,\n type DeviceId,\n type GrantId,\n type HostId,\n type ThreadId,\n type TurnId,\n type UserId,\n} from \"./ids.js\";\n\n/**\n * Who is calling, resolved once per request from its credential by the server's auth\n * provider. Never built from a header: `x-parlor-source` and `x-parlor-client` are\n * routing hints at most.\n */\nexport type Principal =\n | AnonymousPrincipal\n | UserPrincipal\n | AgentPrincipal\n | HostPrincipal;\n\nexport type PrincipalKind = Principal[\"kind\"];\n\nexport interface AnonymousPrincipal {\n readonly kind: \"anonymous\";\n}\n\n/** A person in the app's own UI: a session on one device. */\nexport interface UserPrincipal {\n readonly kind: \"user\";\n readonly userId: UserId;\n readonly sessionId: string;\n readonly deviceId?: DeviceId | undefined;\n}\n\n/**\n * An agent acting for a user. `turn` is set only for an inline agent inside a chat turn;\n * an external MCP client has none.\n */\nexport interface AgentPrincipal {\n readonly kind: \"agent\";\n readonly userId: UserId;\n readonly grantId: GrantId;\n readonly agent: AgentIdentity;\n readonly turn?: TurnBinding | undefined;\n}\n\n/** A user's computer running Parlor Host, holding a grant for one app. */\nexport interface HostPrincipal {\n readonly kind: \"host\";\n readonly userId: UserId;\n readonly grantId: GrantId;\n readonly hostId: HostId;\n}\n\n/** `verified` is false when the name is the MCP client's self-declared `clientInfo.name`. */\nexport interface AgentIdentity {\n readonly name: string;\n readonly verified: boolean;\n}\n\nexport interface TurnBinding {\n readonly threadId: ThreadId;\n readonly turnId: TurnId;\n readonly hostId: HostId;\n readonly clientId: string;\n}\n\nexport type AuthenticatedPrincipal = Exclude<Principal, AnonymousPrincipal>;\n\nexport const ANONYMOUS: AnonymousPrincipal = { kind: \"anonymous\" };\n\n/**\n * Who everyone is when no provider tells people apart: the anonymous browser and the\n * `parlor dev` host and turns. Equal to the default scope, so they share one audience.\n */\nexport const DEV_USER_ID: UserId = asId(\"user\", \"default\");\n\nexport function isAuthenticated(\n principal: Principal,\n): principal is AuthenticatedPrincipal {\n return principal.kind !== \"anonymous\";\n}\n\nexport function userOf(principal: Principal | undefined): UserId | undefined {\n if (principal === undefined) return undefined;\n return principal.kind === \"anonymous\" ? undefined : principal.userId;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAMb,MAAM,aAAa,CAAC;AACrB,OAAO,EAIL,cAAc,GACf,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAMb,MAAM,aAAa,CAAC;AACrB,OAAO,EAIL,cAAc,GACf,MAAM,eAAe,CAAC","sourcesContent":["export {\n invokeAction,\n type InvokeContext,\n type InvokeOptions,\n type InvokeResult,\n type PreparedCall,\n type WriteEvent,\n} from \"./invoke.js\";\nexport {\n type ActionDescriptor,\n type ActionRegistry,\n type ActionsOf,\n createRegistry,\n} from \"./registry.js\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoke.js","sourceRoot":"","sources":["../../src/registry/invoke.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAkB,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAuCvD,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAwB,EACxB,IAAY,EACZ,QAAiB,EACjB,GAAkB,EAClB,OAAO,GAAkB,EAAE;IAE3B,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,WAAW,CAAC,WAAW,EAAE,mBAAmB,IAAI,GAAG,CAAC,CAAC;IAC5E,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,IAAI,SAAS,CAAC;IAC7C,IACE,SAAS,CAAC,IAAI,KAAK,WAAW;QAC9B,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC,EAClD,CAAC;QACD,MAAM,IAAI,WAAW,CAAC,iBAAiB,EAAE,oBAAoB,IAAI,IAAI,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IACjE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,WAAW,CAAC,eAAe,EAAE,sBA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AE,EAAE,GAAG,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,SAAkB,EAAE,CAAC,CAAC;QACtF,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACvE,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QAClB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE;YACrC,GAAG,GAAG;YACN,SAAS;YACT,EAAE,EAAE,IAAI,CAAC,IAAI,EAAW;SACzB,CAAC,CAAC;QACH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAC7C,CAAC;IAED,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;QACnC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QAClB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,EAAW,EAAE,CAAC,CAAC;QAC/E,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC5C,MAAM,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;QACzD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ActionContext, AnyAction, DataProvider, Tag } from \"../action.js\";\nimport { isMutating, needsConfirmation, needsPrincipal } from \"../action.js\";\nimport { ActionError } from \"../errors.js\";\nimport { ANONYMOUS, type Principal } from \"../principal.js\";\nimport { readTagsFor, writeTagsFor } from \"../tags.js\";\nimport type { ActionRegistry } from \"./registry.js\";\n\n/** A caller that names no principal is anonymous: missing identity never widens access. */\nexport type InvokeContext = Omit<ActionContext, \"db\" | \"principal\"> & {\n readonly principal?: Principal | undefined;\n};\n\nexport interface WriteEvent {\n readonly action: AnyAction;\n readonly name: string;\n readonly tags: Tag[];\n readonly ctx: InvokeContext;\n readonly tx: unknown;\n}\n\nexport interface PreparedCall {\n readonly action: AnyAction;\n readonly name: string;\n readonly input: unknown;\n readonly ctx: InvokeContext;\n}\n\nexport interface InvokeOptions {\n readonly data?: DataProvider | undefined;\n readonly onWrite?: ((event: WriteEvent) => Promise<void>) | undefined;\n readonly confirm?: ((call: PreparedCall) => Promise<void>) | undefined;\n /** An enforcing auth provider is installed: non-public actions refuse anonymous callers. */\n readonly enforcing?: boolean | undefined;\n /** Called once, right before `run`: every earlier refusal leaves it uncalled. */\n readonly onRun?: (() => void) | undefined;\n}\n\nexport interface InvokeResult {\n readonly data: unknown;\n readonly reads: Tag[];\n readonly writes: Tag[];\n}\n\nexport async function invokeAction(\n registry: ActionRegistry,\n name: string,\n rawInput: unknown,\n ctx: InvokeContext,\n options: InvokeOptions = {},\n): Promise<InvokeResult> {\n const action = registry.get(name);\n if (!action) throw new ActionError(\"not_found\", `Unknown action \"${name}\"`);\n const principal = ctx.principal ?? ANONYMOUS;\n if (\n principal.kind === \"anonymous\" &&\n needsPrincipal(action, options.enforcing === true)\n ) {\n throw new ActionError(\"unauthenticated\", `Sign in to call \"${name}\".`);\n }\n\n const parsed = await action.input.safeParseAsync(rawInput ?? {});\n if (!parsed.success) {\n throw new ActionError(\"invalid_input\", `Invalid input for \"${name}\"`, {\n issues: parsed.error.issues,\n });\n }\n const input = parsed.data;\n const { data, onWrite, confirm } = options;\n if (needsConfirmation(action, ctx.source)) {\n if (!confirm) {\n throw new ActionError(\n \"confirmation_unavailable\",\n `\"${name}\" needs the user's approval, but nothing here can ask for it.`,\n );\n }\n await confirm({ action, name, input, ctx: { ...ctx, principal } });\n }\n const reads = readTagsFor(action, input);\n\n if (!data) {\n options.onRun?.();\n const result = await action.run(input, { ...ctx, principal, db: undefined as never });\n return { data: result, reads, writes: writeTagsFor(action, result) };\n }\n\n if (!isMutating(action)) {\n options.onRun?.();\n const result = await action.run(input, {\n ...ctx,\n principal,\n db: data.read() as never,\n });\n return { data: result, reads, writes: [] };\n }\n\n return data.transaction(async (tx) => {\n options.onRun?.();\n const result = await action.run(input, { ...ctx, principal, db: tx as never });\n const writes = writeTagsFor(action, result);\n await onWrite?.({ action, name, tags: writes, ctx, tx });\n return { data: result, reads, writes };\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/registry/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAkC,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAmBpF,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAE1C,MAAM,UAAU,cAAc,CAAsB,OAAU;IAC5D,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACrD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CACb,wBAAwB,IAAI,yCAAyC,CACtE,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,iDAAiD,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;IAED,IAAI,WAA2C,CAAC;IAEhD,OAAO;QACL,OAAO;QACP,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,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AAC;QACJ,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,iDAAiD,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;IAED,IAAI,WAA2C,CAAC;IAEhD,OAAO;QACL,OAAO;QACP,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACzE,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QACjC,QAAQ,EAAE,GAAG,EAAE;YACb,WAAW,KAAK,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC/D,IAAI;gBACJ,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC;gBAC5B,GAAG,CAAC,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC9D,WAAW,EAAE,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC;aAC3D,CAAC,CAAC,CAAC;YACJ,OAAO,WAAW,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\n\nimport { type ActionMap, type AnyAction, isAction, isMutating } from \"../action.js\";\n\nexport interface ActionDescriptor {\n readonly name: string;\n readonly description: string;\n readonly mutating: boolean;\n readonly confirm?: boolean | undefined;\n readonly inputSchema: Record<string, unknown>;\n}\n\nexport interface ActionRegistry<T extends ActionMap = ActionMap> {\n readonly actions: Readonly<T>;\n get(name: string): AnyAction | undefined;\n names(): string[];\n describe(): ActionDescriptor[];\n}\n\nexport type ActionsOf<R> = R extends ActionRegistry<infer T> ? T : never;\n\nconst ACTION_NAME = /^[a-z][a-zA-Z0-9]*$/;\n\nexport function createRegistry<T extends ActionMap>(actions: T): ActionRegistry<T> {\n for (const [name, action] of Object.entries(actions)) {\n if (!ACTION_NAME.test(name)) {\n throw new Error(\n `Invalid action name \"${name}\": use camelCase starting with a letter`,\n );\n }\n if (!isAction(action)) {\n throw new Error(`\"${name}\" is not an action: wrap it with defineAction()`);\n }\n }\n\n let descriptors: ActionDescriptor[] | undefined;\n\n return {\n actions,\n get: (name) => (Object.hasOwn(actions, name) ? actions[name] : undefined),\n names: () => Object.keys(actions),\n describe: () => {\n descriptors ??= Object.entries(actions).map(([name, action]) => ({\n name,\n description: action.description,\n mutating: isMutating(action),\n ...(action.confirm === true ? { confirm: true as const } : {}),\n inputSchema: z.toJSONSchema(action.input, { io: \"input\" }),\n }));\n return descriptors;\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-origins.js","sourceRoot":"","sources":["../src/shell-origins.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAsB;IAC9C,mBAAmB;IACnB,wBAAwB;IACxB,yBAAyB;IACzB,uBAAuB;IACvB,mBAAmB;IACnB,kBAAkB;IAClB,mBAAmB;CACpB,CAAC"}
|
|
1
|
+
{"version":3,"file":"shell-origins.js","sourceRoot":"","sources":["../src/shell-origins.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAsB;IAC9C,mBAAmB;IACnB,wBAAwB;IACxB,yBAAyB;IACzB,uBAAuB;IACvB,mBAAmB;IACnB,kBAAkB;IAClB,mBAAmB;CACpB,CAAC","sourcesContent":["export const SHELL_ORIGINS: readonly string[] = [\n \"tauri://localhost\",\n \"http://tauri.localhost\",\n \"https://tauri.localhost\",\n \"capacitor://localhost\",\n \"ionic://localhost\",\n \"http://localhost\",\n \"https://localhost\",\n];\n"]}
|
package/dist/tags.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAkB,MAAM,CAAC,GAAG,CAAC,cAAc,CAAU,CAAC;AAExE,MAAM,UAAU,SAAS,CAAC,MAAiB;IACzC,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAC9C,MAAM,KAAK,GAAG,MAA4D,CAAC;IAC3E,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;IAClD,IAAI,CAAC,IAAI;QACP,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;IAClF,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,CAAM,EAAE,CAAM;IACxC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IAClC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAiB,EAAE,KAAc;IAC3D,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC3B,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,IAAI,OAAO,KAAK,KAAK,UAAU;QAAE,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1D,OAAO,K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,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACvD,MAAM,GAAG,GAAwB,EAAE,CAAC;IACpC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,IAAI,IAAI,GAAG,EAAE,CAAC;YAClD,MAAM,EAAE,GAAI,GAAuB,CAAC,EAAE,CAAC;YACvC,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,OAAO,EAAE,KAAK,QAAQ;gBAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAiB,EAAE,MAAgB;IAC9D,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3B,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import type { AnyAction, Tag, TagSource } from \"./action.js\";\n\nconst DRIZZLE_NAME: unique symbol = Symbol.for(\"drizzle:Name\") as never;\n\nexport function tableName(source: TagSource): string {\n if (typeof source === \"string\") return source;\n const named = source as { [DRIZZLE_NAME]?: string; _?: { name?: string } };\n const name = named[DRIZZLE_NAME] ?? named._?.name;\n if (!name)\n throw new Error(\"Write and read targets must be table names or Drizzle tables\");\n return name;\n}\n\nexport function tagsOverlap(a: Tag, b: Tag): boolean {\n const length = Math.min(a.length, b.length);\n for (let i = 0; i < length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\nexport function readTagsFor(action: AnyAction, input: unknown): Tag[] {\n const reads = action.reads;\n if (!reads) return [];\n if (typeof reads === \"function\") return [...reads(input)];\n return reads.map((source) => [tableName(source)]);\n}\n\nfunction rowIds(result: unknown): (string | number)[] {\n const rows = Array.isArray(result) ? result : [result];\n const ids: (string | number)[] = [];\n for (const row of rows) {\n if (row && typeof row === \"object\" && \"id\" in row) {\n const id = (row as { id: unknown }).id;\n if (typeof id === \"string\" || typeof id === \"number\") ids.push(id);\n }\n }\n return ids;\n}\n\nexport function writeTagsFor(action: AnyAction, result?: unknown): Tag[] {\n const tables = (action.writes ?? []).map(tableName);\n const ids = rowIds(result);\n if (ids.length === 0) return tables.map((table) => [table]);\n return tables.flatMap((table) => ids.map((id) => [table, id]));\n}\n"]}
|