@dxos/compute 0.16.0 → 0.17.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/lib/AiMetering.mjs +1 -0
- package/dist/lib/Hook.mjs +1 -0
- package/dist/lib/Operation.mjs +3 -3
- package/dist/lib/Process.mjs +2 -2
- package/dist/lib/Trace.mjs +1 -1
- package/dist/lib/chunk-AgentIdentity.mjs +1 -1
- package/dist/lib/chunk-AgentService.mjs.map +1 -1
- package/dist/lib/chunk-AiMetering.mjs +77 -0
- package/dist/lib/chunk-AiMetering.mjs.map +1 -0
- package/dist/lib/chunk-Cancellation.mjs +1 -1
- package/dist/lib/chunk-Hook.mjs +78 -0
- package/dist/lib/chunk-Hook.mjs.map +1 -0
- package/dist/lib/chunk-Instructions.mjs +1 -1
- package/dist/lib/chunk-Operation.mjs +169 -5
- package/dist/lib/chunk-Operation.mjs.map +1 -1
- package/dist/lib/chunk-OperationHandlerSet.mjs +1 -1
- package/dist/lib/chunk-OperationRegistry.mjs +1 -1
- package/dist/lib/chunk-OperationRegistry.mjs.map +1 -1
- package/dist/lib/chunk-Process.mjs +18 -10
- package/dist/lib/chunk-Process.mjs.map +1 -1
- package/dist/lib/chunk-Project.mjs +52 -24
- package/dist/lib/chunk-Project.mjs.map +1 -1
- package/dist/lib/chunk-Reducer.mjs +827 -0
- package/dist/lib/chunk-Reducer.mjs.map +1 -0
- package/dist/lib/chunk-Routine.mjs +1 -1
- package/dist/lib/chunk-Runnable.mjs +1 -1
- package/dist/lib/chunk-ServiceResolver.mjs +1 -1
- package/dist/lib/chunk-Skill.mjs +10 -47
- package/dist/lib/chunk-Skill.mjs.map +1 -1
- package/dist/lib/chunk-Spec.mjs +49 -0
- package/dist/lib/chunk-Spec.mjs.map +1 -0
- package/dist/lib/chunk-SpecReview.mjs +98 -0
- package/dist/lib/chunk-SpecReview.mjs.map +1 -0
- package/dist/lib/chunk-SqlService.mjs.map +1 -1
- package/dist/lib/chunk-StorageService.mjs +1 -1
- package/dist/lib/chunk-Template.mjs +2 -2
- package/dist/lib/chunk-Trace.mjs +97 -13
- package/dist/lib/chunk-Trace.mjs.map +1 -1
- package/dist/lib/chunk-Trajectory.mjs +326 -0
- package/dist/lib/chunk-Trajectory.mjs.map +1 -0
- package/dist/lib/chunk-Transcript.mjs +84 -0
- package/dist/lib/chunk-Transcript.mjs.map +1 -0
- package/dist/lib/chunk-definitions.mjs +1 -1
- package/dist/lib/errors.mjs +3 -1
- package/dist/lib/errors.mjs.map +1 -1
- package/dist/lib/index.mjs +14 -8
- package/dist/lib/testing.mjs +2 -2
- package/dist/lib/trajectory/Reducer.mjs +1 -0
- package/dist/lib/trajectory/Trajectory.mjs +1 -0
- package/dist/lib/trajectory/Transcript.mjs +1 -0
- package/dist/lib/types/Project.mjs +1 -1
- package/dist/lib/types/Skill.mjs +1 -1
- package/dist/lib/types/Spec.mjs +1 -0
- package/dist/lib/types/SpecReview.mjs +1 -0
- package/dist/types/src/AgentService.d.ts +9 -0
- package/dist/types/src/AgentService.d.ts.map +1 -1
- package/dist/types/src/AiMetering.d.ts +23 -0
- package/dist/types/src/AiMetering.d.ts.map +1 -0
- package/dist/types/src/AiMetering.test.d.ts +2 -0
- package/dist/types/src/AiMetering.test.d.ts.map +1 -0
- package/dist/types/src/Hook.d.ts +84 -0
- package/dist/types/src/Hook.d.ts.map +1 -0
- package/dist/types/src/Hook.test.d.ts +2 -0
- package/dist/types/src/Hook.test.d.ts.map +1 -0
- package/dist/types/src/Operation.d.ts +276 -2
- package/dist/types/src/Operation.d.ts.map +1 -1
- package/dist/types/src/Process.d.ts +26 -4
- package/dist/types/src/Process.d.ts.map +1 -1
- package/dist/types/src/Script.test.d.ts +2 -0
- package/dist/types/src/Script.test.d.ts.map +1 -0
- package/dist/types/src/Trace.d.ts +103 -1
- package/dist/types/src/Trace.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +30 -0
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/trajectory/Reducer.d.ts +191 -0
- package/dist/types/src/trajectory/Reducer.d.ts.map +1 -0
- package/dist/types/src/trajectory/Reducer.test.d.ts +2 -0
- package/dist/types/src/trajectory/Reducer.test.d.ts.map +1 -0
- package/dist/types/src/trajectory/Trajectory.d.ts +3211 -0
- package/dist/types/src/trajectory/Trajectory.d.ts.map +1 -0
- package/dist/types/src/trajectory/Trajectory.test.d.ts +2 -0
- package/dist/types/src/trajectory/Trajectory.test.d.ts.map +1 -0
- package/dist/types/src/trajectory/Transcript.d.ts +40 -0
- package/dist/types/src/trajectory/Transcript.d.ts.map +1 -0
- package/dist/types/src/trajectory/index.d.ts +4 -0
- package/dist/types/src/trajectory/index.d.ts.map +1 -0
- package/dist/types/src/trajectory/light-threads.test.d.ts +2 -0
- package/dist/types/src/trajectory/light-threads.test.d.ts.map +1 -0
- package/dist/types/src/trajectory/samples.test.d.ts +2 -0
- package/dist/types/src/trajectory/samples.test.d.ts.map +1 -0
- package/dist/types/src/types/Project.d.ts +11 -12
- package/dist/types/src/types/Project.d.ts.map +1 -1
- package/dist/types/src/types/Skill.d.ts +6 -51
- package/dist/types/src/types/Skill.d.ts.map +1 -1
- package/dist/types/src/types/Spec.d.ts +26 -0
- package/dist/types/src/types/Spec.d.ts.map +1 -0
- package/dist/types/src/types/SpecReview.d.ts +76 -0
- package/dist/types/src/types/SpecReview.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +59 -26
- package/src/AgentService.ts +9 -0
- package/src/AiMetering.test.ts +89 -0
- package/src/AiMetering.ts +93 -0
- package/src/Hook.test.ts +75 -0
- package/src/Hook.ts +154 -0
- package/src/Operation.test.ts +23 -0
- package/src/Operation.ts +334 -0
- package/src/Process.ts +33 -6
- package/src/Script.test.ts +74 -0
- package/src/Trace.ts +97 -4
- package/src/errors.ts +3 -0
- package/src/index.ts +3 -1
- package/src/trajectory/Reducer.test.ts +575 -0
- package/src/trajectory/Reducer.ts +1026 -0
- package/src/trajectory/Trajectory.test.ts +114 -0
- package/src/trajectory/Trajectory.ts +440 -0
- package/src/trajectory/Transcript.ts +113 -0
- package/src/trajectory/index.ts +7 -0
- package/src/trajectory/light-threads.test.ts +310 -0
- package/src/trajectory/samples.test.ts +285 -0
- package/src/types/Project.test.ts +2 -1
- package/src/types/Project.ts +43 -27
- package/src/types/Skill.ts +6 -61
- package/src/types/Spec.ts +68 -0
- package/src/types/SpecReview.ts +98 -0
- package/src/types/index.ts +2 -0
- package/dist/lib/McpServer.mjs +0 -1
- package/dist/lib/chunk-McpServer.mjs +0 -124
- package/dist/lib/chunk-McpServer.mjs.map +0 -1
- package/dist/types/src/McpServer.d.ts +0 -113
- package/dist/types/src/McpServer.d.ts.map +0 -1
- package/src/McpServer.ts +0 -142
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as metered, r as summarize } from "./chunk-AiMetering.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as Output, r as SettingsAnnotation, i as followUp, a as forPlugin, o as isOnByDefault, s as resolve, c as setEnabled } from "./chunk-Hook.mjs";
|
package/dist/lib/Operation.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { FunctionError, FunctionNotFoundError, InvalidOperationInputError, InvalidOperationOutputError, InvokerNotInitializedError, NoHandlerError } from "./errors.mjs";
|
|
2
|
-
import { A as
|
|
3
|
-
export { DefinitionTypeId, DurableDefinitionTypeId, DurableTypeId, FunctionError, FunctionNotFoundError, IdempotentAnnotation, InvalidOperationInputError, InvalidOperationOutputError, InvokerNotInitializedError, Label, LazyHandlerTypeId, MutationAnnotation, NoHandlerError, NotifyOptions, NotifyOptionsAnnotation, PersistentOperation, PersistentOperation_v0_1_0, Service, VisibleAnnotation, annotate, deserialize, findToolNameCollisions, getKey, getMutation, getVersion, idempotent, invoke, isDurable, isDurableDefinition, isIdempotent, isLazyHandler, isOperationDefinition, isOperationWithHandler, isVisible, lazyHandler, make, makeDurable, migrations, mutation, opaqueHandler, prepare, runAgain, schedule, serializable, serialize, setFrom, toolName, toolNameFromKey, tryToolNameFromKey, visible, withDurableHandler, withHandler, withInvocationOptions };
|
|
1
|
+
import { FunctionError, FunctionNotFoundError, InvalidOperationInputError, InvalidOperationOutputError, InvokerNotInitializedError, NoHandlerError, OperationDeniedError } from "./errors.mjs";
|
|
2
|
+
import { $ as runAgain, A as getVersion, B as isOperationWithHandler, C as annotate, D as getKey, E as getConsentPreview, F as isDurableDefinition, G as lazyHandler, H as isScriptDialect, I as isIdempotent, J as makeScript, K as make, L as isInlineScript, M as inlineScript, N as invoke, O as getMutation, P as isDurable, Q as prepare, R as isLazyHandler, S as VisibleAnnotation, T as findToolNameCollisions, U as isScriptRef, V as isScript, W as isVisible, X as mutation, Y as migrations, Z as opaqueHandler, _ as ScriptDialects, a as IdempotentAnnotation, at as serialize, b as ScriptStats, c as MutationAnnotation, ct as toolNameFromKey, dt as withDurableHandler, et as schedule, f as PersistentOperation, ft as withHandler, g as ScriptDialect, h as ScriptDefinitionTypeId, i as DurableTypeId, it as serializable, j as idempotent, k as getRequirements, l as NotifyOptions, lt as tryToolNameFromKey, m as RequiresAnnotation, n as DefinitionTypeId, nt as scriptRef, o as Label, ot as setFrom, p as PersistentOperation_v0_1_0, pt as withInvocationOptions, q as makeDurable, r as DurableDefinitionTypeId, rt as scriptRequest, s as LazyHandlerTypeId, st as toolName, t as ConsentPreviewAnnotation, tt as scriptDialectOf, u as NotifyOptionsAnnotation, ut as visible, v as ScriptError, w as deserialize, x as Service, y as ScriptResult, z as isOperationDefinition } from "./chunk-Operation.mjs";
|
|
3
|
+
export { ConsentPreviewAnnotation, DefinitionTypeId, DurableDefinitionTypeId, DurableTypeId, FunctionError, FunctionNotFoundError, IdempotentAnnotation, InvalidOperationInputError, InvalidOperationOutputError, InvokerNotInitializedError, Label, LazyHandlerTypeId, MutationAnnotation, NoHandlerError, NotifyOptions, NotifyOptionsAnnotation, OperationDeniedError, PersistentOperation, PersistentOperation_v0_1_0, RequiresAnnotation, ScriptDefinitionTypeId, ScriptDialect, ScriptDialects, ScriptError, ScriptResult, ScriptStats, Service, VisibleAnnotation, annotate, deserialize, findToolNameCollisions, getConsentPreview, getKey, getMutation, getRequirements, getVersion, idempotent, inlineScript, invoke, isDurable, isDurableDefinition, isIdempotent, isInlineScript, isLazyHandler, isOperationDefinition, isOperationWithHandler, isScript, isScriptDialect, isScriptRef, isVisible, lazyHandler, make, makeDurable, makeScript, migrations, mutation, opaqueHandler, prepare, runAgain, schedule, scriptDialectOf, scriptRef, scriptRequest, serializable, serialize, setFrom, toolName, toolNameFromKey, tryToolNameFromKey, visible, withDurableHandler, withHandler, withInvocationOptions };
|
package/dist/lib/Process.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { RUN_AGAIN_ERROR_CODE, RUN_AGAIN_MESSAGE, RunAgainError } from "./errors.mjs";
|
|
2
|
-
import { _ as
|
|
3
|
-
export { EnvironmentService, ExitedEvent, HarnessHostAnnotation, ID, ManagerService, NotifyAnnotation, RUN_AGAIN_ERROR_CODE, RUN_AGAIN_MESSAGE, RunAgainError, SpawnedEvent, State, TargetAnnotation, awaitOutput, currentEnvironment, isExited, isHarnessHost, isTerminal, listFromTree, matchesFilter, prettyProcessTree, spawn };
|
|
2
|
+
import { _ as isTerminal, a as ID, b as prettyProcessTree, d as TargetAnnotation, f as awaitOutput, g as isHarnessHost, h as isExited, i as HarnessHostAnnotation, l as SpawnedEvent, m as currentEnvironment, n as ExitedEvent, o as ManagerService, p as bothGuards, r as GuardService, s as NotifyAnnotation, t as EnvironmentService, u as State, v as listFromTree, x as spawn, y as matchesFilter } from "./chunk-Process.mjs";
|
|
3
|
+
export { EnvironmentService, ExitedEvent, GuardService, HarnessHostAnnotation, ID, ManagerService, NotifyAnnotation, RUN_AGAIN_ERROR_CODE, RUN_AGAIN_MESSAGE, RunAgainError, SpawnedEvent, State, TargetAnnotation, awaitOutput, bothGuards, currentEnvironment, isExited, isHarnessHost, isTerminal, listFromTree, matchesFilter, prettyProcessTree, spawn };
|
package/dist/lib/Trace.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as
|
|
1
|
+
export { t as AgentHooksResolved, n as AgentRequestBegin, r as AgentRequestEnd, i as CommonRuntimeName, a as CompleteBlock, o as CurrentThread, s as DelegationCompleted, c as DelegationSpawned, l as Event, u as EventType, d as McpServerError, f as Message, p as MessageData, m as Meta, h as ModelCall, g as OperationEnd, _ as OperationInput, v as OperationOutput, y as OperationStart, b as PartialBlock, x as QuestionAnswered, S as QuestionAsked, C as RequestPhase, w as RequestPhaseName, T as RuntimeName, E as StatusCancelled, D as StatusComplete, O as StatusError, k as StatusFailed, A as StatusUpdate, j as TRACE_MESSAGE_TYPE_URL, M as TaskStatusChanged, N as TraceService, P as TraceSink, I as decodeTraceMessage, L as emitRequestPhase, R as emitStatus, z as encodeTraceMessage, B as flatten, V as isEdgeRuntime, H as isOfType, U as layerConsole, W as layerNoop, G as matchesFilter, K as mergeSinks, q as messageToTags, J as noopSink, Y as noopWriter, X as subscriptionTagForFilter, Z as testTraceService, Q as write, $ as writerLayerNoop } from "./chunk-Trace.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
-
import * as Effect from "effect/Effect";
|
|
3
2
|
import * as Option from "effect/Option";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as Context from "effect/Context";
|
|
5
5
|
//#region src/AgentIdentity.ts
|
|
6
6
|
var AgentIdentity_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-AgentService.mjs","names":[],"sources":["../../src/AgentService.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport type * as Atom from 'effect/reactivity/Atom';\nimport type * as Stream from 'effect/Stream';\n\nimport type { SessionConfig } from '@dxos/ai';\nimport type { Database, Feed, Obj, Ref } from '@dxos/echo';\nimport { DXN } from '@dxos/keys';\nimport type { ContentBlock } from '@dxos/types';\n\nimport type * as Process from './Process.ts';\nimport type * as Trace from './Trace.ts';\nimport { Instructions } from './types/index.ts';\n\n/**\n * Structural view of the `Chat` object (`@dxos/assistant/Chat`): the durable conversation an agent\n * runs on, carrying its message feed and the instructions steering it. Declared structurally\n * because `@dxos/assistant` sits above this package.\n */\nexport interface Conversation extends Obj.Unknown {\n readonly feed: Ref.Ref<Feed.Feed>;\n readonly instructions?: Ref.Ref<Instructions.Instructions>;\n /** How the conversation runs (its model); an unset model runs the agent's default. */\n readonly session?: SessionConfig.SessionConfig;\n}\n\n/**\n * Service interface for the agent session manager.\n * Implementation lives in @dxos/functions-runtime.\n */\nexport interface Service {\n /**\n * Gets or creates a session for a chat. The agent process is bound to the chat (its spawn\n * target), reading the feed, the steering instructions and the model from it.\n */\n getSession: (chat: Conversation, options?: GetSessionOptions) => Effect.Effect<Session, never, Database.Service>;\n\n /**\n * Hydrates agent processes persisted by a previous session.\n * Each record is rehydrated with a fresh process built from the layer options.\n */\n hydrate: () => Effect.Effect<void>;\n}\n\nexport class AgentService extends Context.Service<AgentService, Service>()('@dxos/functions-runtime/AgentService') {}\n\n/** Re-exported so callers importing this module as a namespace avoid `AgentService.AgentService.key`. */\nexport const key = AgentService.key;\n\n/**\n * Who a prompt is from, when it is not the session's own reader: the plain-data subset of `Actor`,\n * because the prompt crosses a JSON boundary (a remote process) where a `Ref` cannot be supplied.\n */\nexport type PromptSender = {\n readonly name?: string;\n readonly identityDid?: string;\n readonly email?: string;\n};\n\nexport type SubmitPromptOptions = {\n /** Recorded on the appended user message; a named sender is shown to the model as the speaker. */\n readonly sender?: PromptSender;\n};\n\n/**\n * Handle to an agent session.\n */\nexport interface Session {\n /**\n * The chat that the session is associated with.\n */\n readonly chat: Conversation;\n\n /**\n * The feed carrying the chat's messages.\n */\n readonly feed: Feed.Feed;\n\n /**\n * Gets the context objects from the agent.\n */\n getContext: () => Effect.Effect<Ref.Ref<Obj.Unknown>[], never, Database.Service>;\n\n /**\n * Adds context objects to the agent.\n */\n addContext: (context: Ref.Ref<Obj.Unknown>[]) => Effect.Effect<void, never, Database.Service>;\n\n /**\n * Submit a turn: a plain user prompt, or pre-built content blocks (e.g. synthetic context + prompt).\n */\n submitPrompt: (prompt: string | ContentBlock.Any[], options?: SubmitPromptOptions) => Effect.Effect<void>;\n\n /**\n * True while the agent is working on a turn (running, or waiting on a tool call or alarm); false\n * when it is idle awaiting input, or terminal.\n */\n readonly running: Atom.Atom<boolean>;\n\n /**\n * Wait until agent has completed its work.\n */\n waitForCompletion: () => Effect.Effect<void>;\n\n /**\n * Terminates the agent process and clears its durable storage.\n */\n terminate: () => Effect.Effect<void>;\n\n /**\n * Subscribe to ephemeral trace events (e.g., streaming partial messages).\n * Replays buffered events, then streams new ones until the process ends.\n *\n * When forking a collector from a short-lived parent (e.g. `useEffect` +\n * `runPromise(Effect.forEach(subscribe))`), use {@link Effect.forkDetach} so the\n * stream survives after the parent scope closes; interrupt it on dispose.\n */\n subscribeEphemeral: (options?: Process.SubscribeEphemeralOptions) => Stream.Stream<Trace.Message>;\n}\n\nexport const getSession = (...args: Parameters<Context.Service.Shape<typeof AgentService>['getSession']>) =>\n AgentService.use((service) => service.getSession(...args));\n\nexport const hydrate = (...args: Parameters<Context.Service.Shape<typeof AgentService>['hydrate']>) =>\n AgentService.use((service) => service.hydrate(...args));\n\nexport interface GetSessionOptions {\n // The model is read off the chat (see `Conversation.session`), but the catalog's shared model ids are\n // served by several providers, so the provider must still accompany it into the agent process —\n // the id alone does not identify a resolver.\n readonly provider?: DXN.DXN;\n readonly systemPrompt?: string;\n /**\n * Where the agent runs. `local` executes it in this runtime; `edge` spawns it on the remote host\n * reached through `RemoteProcessManager.Service`, so the conversation continues with the client\n * closed. Read at spawn only, like `model` — moving a live conversation between runtimes would\n * mean handing one process's durable state to another.\n *\n * @default 'local'\n */\n readonly location?: AgentLocation;\n}\n\nexport type AgentLocation = 'local' | 'edge';\n"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"chunk-AgentService.mjs","names":[],"sources":["../../src/AgentService.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport type * as Atom from 'effect/reactivity/Atom';\nimport type * as Stream from 'effect/Stream';\n\nimport type { SessionConfig } from '@dxos/ai';\nimport type { Database, Feed, Obj, Ref } from '@dxos/echo';\nimport { DXN } from '@dxos/keys';\nimport type { ContentBlock } from '@dxos/types';\n\nimport type * as Process from './Process.ts';\nimport type * as Trace from './Trace.ts';\nimport type * as Trajectory from './trajectory/Trajectory.ts';\nimport { Instructions } from './types/index.ts';\n\n/**\n * Structural view of the `Chat` object (`@dxos/assistant/Chat`): the durable conversation an agent\n * runs on, carrying its message feed and the instructions steering it. Declared structurally\n * because `@dxos/assistant` sits above this package.\n */\nexport interface Conversation extends Obj.Unknown {\n readonly feed: Ref.Ref<Feed.Feed>;\n readonly instructions?: Ref.Ref<Instructions.Instructions>;\n /** How the conversation runs (its model); an unset model runs the agent's default. */\n readonly session?: SessionConfig.SessionConfig;\n}\n\n/**\n * Service interface for the agent session manager.\n * Implementation lives in @dxos/functions-runtime.\n */\nexport interface Service {\n /**\n * Gets or creates a session for a chat. The agent process is bound to the chat (its spawn\n * target), reading the feed, the steering instructions and the model from it.\n */\n getSession: (chat: Conversation, options?: GetSessionOptions) => Effect.Effect<Session, never, Database.Service>;\n\n /**\n * Hydrates agent processes persisted by a previous session.\n * Each record is rehydrated with a fresh process built from the layer options.\n */\n hydrate: () => Effect.Effect<void>;\n}\n\nexport class AgentService extends Context.Service<AgentService, Service>()('@dxos/functions-runtime/AgentService') {}\n\n/** Re-exported so callers importing this module as a namespace avoid `AgentService.AgentService.key`. */\nexport const key = AgentService.key;\n\n/**\n * Who a prompt is from, when it is not the session's own reader: the plain-data subset of `Actor`,\n * because the prompt crosses a JSON boundary (a remote process) where a `Ref` cannot be supplied.\n */\nexport type PromptSender = {\n readonly name?: string;\n readonly identityDid?: string;\n readonly email?: string;\n};\n\nexport type SubmitPromptOptions = {\n /** Recorded on the appended user message; a named sender is shown to the model as the speaker. */\n readonly sender?: PromptSender;\n /** The fork to send the prompt into; main when absent. */\n readonly thread?: Trajectory.ThreadId;\n};\n\n/**\n * Handle to an agent session.\n */\nexport interface Session {\n /**\n * The chat that the session is associated with.\n */\n readonly chat: Conversation;\n\n /**\n * The feed carrying the chat's messages.\n */\n readonly feed: Feed.Feed;\n\n /**\n * Gets the context objects from the agent.\n */\n getContext: () => Effect.Effect<Ref.Ref<Obj.Unknown>[], never, Database.Service>;\n\n /**\n * Adds context objects to the agent.\n */\n addContext: (context: Ref.Ref<Obj.Unknown>[]) => Effect.Effect<void, never, Database.Service>;\n\n /**\n * Submit a turn: a plain user prompt, or pre-built content blocks (e.g. synthetic context + prompt).\n */\n submitPrompt: (prompt: string | ContentBlock.Any[], options?: SubmitPromptOptions) => Effect.Effect<void>;\n\n /**\n * True while the agent is working on a turn (running, or waiting on a tool call or alarm); false\n * when it is idle awaiting input, or terminal.\n */\n readonly running: Atom.Atom<boolean>;\n\n /**\n * Wait until agent has completed its work.\n */\n waitForCompletion: () => Effect.Effect<void>;\n\n /**\n * Terminates the agent process and clears its durable storage.\n */\n terminate: () => Effect.Effect<void>;\n\n /**\n * Subscribe to ephemeral trace events (e.g., streaming partial messages).\n * Replays buffered events, then streams new ones until the process ends.\n *\n * When forking a collector from a short-lived parent (e.g. `useEffect` +\n * `runPromise(Effect.forEach(subscribe))`), use {@link Effect.forkDetach} so the\n * stream survives after the parent scope closes; interrupt it on dispose.\n */\n subscribeEphemeral: (options?: Process.SubscribeEphemeralOptions) => Stream.Stream<Trace.Message>;\n}\n\nexport const getSession = (...args: Parameters<Context.Service.Shape<typeof AgentService>['getSession']>) =>\n AgentService.use((service) => service.getSession(...args));\n\nexport const hydrate = (...args: Parameters<Context.Service.Shape<typeof AgentService>['hydrate']>) =>\n AgentService.use((service) => service.hydrate(...args));\n\nexport interface GetSessionOptions {\n // The model is read off the chat (see `Conversation.session`), but the catalog's shared model ids are\n // served by several providers, so the provider must still accompany it into the agent process —\n // the id alone does not identify a resolver.\n readonly provider?: DXN.DXN;\n readonly systemPrompt?: string;\n /**\n * Where the agent runs. `local` executes it in this runtime; `edge` spawns it on the remote host\n * reached through `RemoteProcessManager.Service`, so the conversation continues with the client\n * closed. Read at spawn only, like `model` — moving a live conversation between runtimes would\n * mean handing one process's durable state to another.\n *\n * @default 'local'\n */\n readonly location?: AgentLocation;\n /**\n * Admits the operations the agent and its tool calls invoke that declare requirements\n * (`Process.SpawnOptions.guard`). Bound at spawn, so a session asked for with a different guard\n * runs on a fresh process. A guard is a closure and never reaches an `edge` process.\n */\n readonly guard?: Process.Guard;\n}\n\nexport type AgentLocation = 'local' | 'edge';\n"],"mappings":";;;;;;;;;AAmDA,IAAa,eAAb,cAAkC,QAAQ,QAA+B,CAAC,CAAC,sCAAsC,CAAC,CAAC,CAAC;;AAGpH,IAAa,MAAM,aAAa;AA2EhC,IAAa,cAAc,GAAG,SAC5B,aAAa,KAAK,YAAY,QAAQ,WAAW,GAAG,IAAI,CAAC;AAE3D,IAAa,WAAW,GAAG,SACzB,aAAa,KAAK,YAAY,QAAQ,QAAQ,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
+
import { H as isOfType, N as TraceService, h as ModelCall, o as CurrentThread } from "./chunk-Trace.mjs";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { AiService, AiUsage } from "@dxos/ai";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import * as Fiber from "effect/Fiber";
|
|
7
|
+
//#region src/AiMetering.ts
|
|
8
|
+
var AiMetering_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
+
metered: () => metered,
|
|
10
|
+
summarize: () => summarize
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* An `AiService` that writes a {@link Trace.ModelCall} event for every language-model call made
|
|
14
|
+
* through the `AiService` below it, so a run's token usage (and, with catalog prices, its cost) can
|
|
15
|
+
* be read back from its trace. Lives here rather than in `@dxos/ai`, which cannot depend on the trace.
|
|
16
|
+
*/
|
|
17
|
+
var metered = Layer.effect(AiService.AiService, Effect.gen(function* () {
|
|
18
|
+
const upstream = yield* AiService.AiService;
|
|
19
|
+
const writer = yield* TraceService;
|
|
20
|
+
return AiUsage.instrument(upstream, (call) => {
|
|
21
|
+
const thread = Fiber.getCurrent()?.getRef(CurrentThread);
|
|
22
|
+
writer.write(ModelCall, {
|
|
23
|
+
modelId: call.modelId,
|
|
24
|
+
model: call.model,
|
|
25
|
+
provider: call.provider,
|
|
26
|
+
stage: call.stage,
|
|
27
|
+
spanName: call.spanName,
|
|
28
|
+
inputTokens: call.inputTokens,
|
|
29
|
+
outputTokens: call.outputTokens,
|
|
30
|
+
cacheReadTokens: call.cacheReadTokens,
|
|
31
|
+
cacheWriteTokens: call.cacheWriteTokens,
|
|
32
|
+
start: call.start,
|
|
33
|
+
end: call.end
|
|
34
|
+
}, thread === void 0 ? void 0 : { thread });
|
|
35
|
+
});
|
|
36
|
+
}));
|
|
37
|
+
/**
|
|
38
|
+
* Totals of the {@link Trace.ModelCall} events among `events`, one per model and stage, priced from
|
|
39
|
+
* the model catalog.
|
|
40
|
+
*/
|
|
41
|
+
var summarize = (events) => {
|
|
42
|
+
const totals = /* @__PURE__ */ new Map();
|
|
43
|
+
for (const event of events) {
|
|
44
|
+
if (!isOfType(ModelCall, event)) continue;
|
|
45
|
+
const call = event.data;
|
|
46
|
+
const key = `${call.modelId ?? call.model}\u0000${call.stage ?? ""}`;
|
|
47
|
+
const total = totals.get(key) ?? {
|
|
48
|
+
modelId: call.modelId,
|
|
49
|
+
model: call.model,
|
|
50
|
+
stage: call.stage,
|
|
51
|
+
calls: 0,
|
|
52
|
+
inputTokens: 0,
|
|
53
|
+
outputTokens: 0,
|
|
54
|
+
cacheReadTokens: 0,
|
|
55
|
+
cacheWriteTokens: 0
|
|
56
|
+
};
|
|
57
|
+
totals.set(key, {
|
|
58
|
+
...total,
|
|
59
|
+
calls: total.calls + 1,
|
|
60
|
+
inputTokens: total.inputTokens + call.inputTokens,
|
|
61
|
+
outputTokens: total.outputTokens + call.outputTokens,
|
|
62
|
+
cacheReadTokens: total.cacheReadTokens + call.cacheReadTokens,
|
|
63
|
+
cacheWriteTokens: total.cacheWriteTokens + call.cacheWriteTokens
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return [...totals.values()].map(({ modelId, ...total }) => {
|
|
67
|
+
const pricing = modelId === void 0 ? void 0 : AiUsage.pricingOf(modelId);
|
|
68
|
+
return pricing === void 0 ? total : {
|
|
69
|
+
...total,
|
|
70
|
+
cost: AiUsage.cost(total, pricing)
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
export { metered as n, summarize as r, AiMetering_exports as t };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=chunk-AiMetering.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-AiMetering.mjs","names":["Trace.TraceService","Trace.CurrentThread","Trace.ModelCall","Trace.isOfType"],"sources":["../../src/AiMetering.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Effect from 'effect/Effect';\nimport * as Fiber from 'effect/Fiber';\nimport * as Layer from 'effect/Layer';\n\nimport { AiService, AiUsage } from '@dxos/ai';\n\nimport * as Trace from './Trace.ts';\n\n/**\n * An `AiService` that writes a {@link Trace.ModelCall} event for every language-model call made\n * through the `AiService` below it, so a run's token usage (and, with catalog prices, its cost) can\n * be read back from its trace. Lives here rather than in `@dxos/ai`, which cannot depend on the trace.\n */\nexport const metered: Layer.Layer<AiService.AiService, never, AiService.AiService | Trace.TraceService> = Layer.effect(\n AiService.AiService,\n Effect.gen(function* () {\n const upstream = yield* AiService.AiService;\n const writer = yield* Trace.TraceService;\n return AiUsage.instrument(upstream, (call) => {\n // The recorder runs synchronously on the model call's fiber, so the caller's thread is readable here.\n const thread = Fiber.getCurrent()?.getRef(Trace.CurrentThread);\n writer.write(\n Trace.ModelCall,\n {\n modelId: call.modelId,\n model: call.model,\n provider: call.provider,\n stage: call.stage,\n spanName: call.spanName,\n inputTokens: call.inputTokens,\n outputTokens: call.outputTokens,\n cacheReadTokens: call.cacheReadTokens,\n cacheWriteTokens: call.cacheWriteTokens,\n start: call.start,\n end: call.end,\n },\n thread === undefined ? undefined : { thread },\n );\n });\n }),\n);\n\n/** Token and dollar totals for one model (and stage), as {@link summarize} reports them. */\nexport type Total = AiUsage.Tokens & {\n readonly model: string;\n readonly stage?: string;\n readonly calls: number;\n /** USD at the catalog's list price; undefined when the catalog has no price for the model. */\n readonly cost?: number;\n};\n\n/**\n * Totals of the {@link Trace.ModelCall} events among `events`, one per model and stage, priced from\n * the model catalog.\n */\nexport const summarize = (events: Iterable<Trace.Event>): Total[] => {\n const totals = new Map<string, Total & { readonly modelId?: string }>();\n for (const event of events) {\n if (!Trace.isOfType(Trace.ModelCall, event)) {\n continue;\n }\n const call = event.data;\n const key = `${call.modelId ?? call.model}\\u0000${call.stage ?? ''}`;\n const total = totals.get(key) ?? {\n modelId: call.modelId,\n model: call.model,\n stage: call.stage,\n calls: 0,\n inputTokens: 0,\n outputTokens: 0,\n cacheReadTokens: 0,\n cacheWriteTokens: 0,\n };\n totals.set(key, {\n ...total,\n calls: total.calls + 1,\n inputTokens: total.inputTokens + call.inputTokens,\n outputTokens: total.outputTokens + call.outputTokens,\n cacheReadTokens: total.cacheReadTokens + call.cacheReadTokens,\n cacheWriteTokens: total.cacheWriteTokens + call.cacheWriteTokens,\n });\n }\n return [...totals.values()].map(({ modelId, ...total }) => {\n const pricing = modelId === undefined ? undefined : AiUsage.pricingOf(modelId);\n return pricing === undefined ? total : { ...total, cost: AiUsage.cost(total, pricing) };\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,IAAa,UAA6F,MAAM,OAC9G,UAAU,WACV,OAAO,IAAI,aAAa;CACtB,MAAM,WAAW,OAAO,UAAU;CAClC,MAAM,SAAS,OAAOA;CACtB,OAAO,QAAQ,WAAW,WAAW,SAAS;EAE5C,MAAM,SAAS,MAAM,WAAW,CAAC,EAAE,OAAOC,aAAmB;EAC7D,OAAO,MACLC,WACA;GACE,SAAS,KAAK;GACd,OAAO,KAAK;GACZ,UAAU,KAAK;GACf,OAAO,KAAK;GACZ,UAAU,KAAK;GACf,aAAa,KAAK;GAClB,cAAc,KAAK;GACnB,iBAAiB,KAAK;GACtB,kBAAkB,KAAK;GACvB,OAAO,KAAK;GACZ,KAAK,KAAK;EACZ,GACA,WAAW,KAAA,IAAY,KAAA,IAAY,EAAE,OAAO,CAC9C;CACF,CAAC;AACH,CAAC,CACH;;;;;AAeA,IAAa,aAAa,WAA2C;CACnE,MAAM,yBAAS,IAAI,IAAmD;CACtE,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,CAACC,SAAeD,WAAiB,KAAK,GACxC;EAEF,MAAM,OAAO,MAAM;EACnB,MAAM,MAAM,GAAG,KAAK,WAAW,KAAK,MAAM,QAAQ,KAAK,SAAS;EAChE,MAAM,QAAQ,OAAO,IAAI,GAAG,KAAK;GAC/B,SAAS,KAAK;GACd,OAAO,KAAK;GACZ,OAAO,KAAK;GACZ,OAAO;GACP,aAAa;GACb,cAAc;GACd,iBAAiB;GACjB,kBAAkB;EACpB;EACA,OAAO,IAAI,KAAK;GACd,GAAG;GACH,OAAO,MAAM,QAAQ;GACrB,aAAa,MAAM,cAAc,KAAK;GACtC,cAAc,MAAM,eAAe,KAAK;GACxC,iBAAiB,MAAM,kBAAkB,KAAK;GAC9C,kBAAkB,MAAM,mBAAmB,KAAK;EAClD,CAAC;CACH;CACA,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,SAAS,GAAG,YAAY;EACzD,MAAM,UAAU,YAAY,KAAA,IAAY,KAAA,IAAY,QAAQ,UAAU,OAAO;EAC7E,OAAO,YAAY,KAAA,IAAY,QAAQ;GAAE,GAAG;GAAO,MAAM,QAAQ,KAAK,OAAO,OAAO;EAAE;CACxF,CAAC;AACH"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
-
import * as Effect from "effect/Effect";
|
|
3
2
|
import * as Option from "effect/Option";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as Context from "effect/Context";
|
|
5
5
|
//#region src/Cancellation.ts
|
|
6
6
|
var Cancellation_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
+
import * as Option from "effect/Option";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import { Annotation, Obj } from "@dxos/echo";
|
|
5
|
+
//#region src/Hook.ts
|
|
6
|
+
var Hook_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
Output: () => Output,
|
|
8
|
+
SettingsAnnotation: () => SettingsAnnotation,
|
|
9
|
+
followUp: () => followUp,
|
|
10
|
+
forPlugin: () => forPlugin,
|
|
11
|
+
isOnByDefault: () => isOnByDefault,
|
|
12
|
+
resolve: () => resolve,
|
|
13
|
+
setEnabled: () => setEnabled
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* What a hook returns. A `followUp` is queued to the agent as a synthetic prompt, so the request
|
|
17
|
+
* continues instead of ending — e.g. a reminder that the plan still has open tasks.
|
|
18
|
+
*/
|
|
19
|
+
var Output = Schema.Struct({ followUp: Schema.optional(Schema.String) });
|
|
20
|
+
/** `hooks` as `plugin` contributes them. */
|
|
21
|
+
var forPlugin = (plugin, hooks) => hooks.map((hook) => ({
|
|
22
|
+
...hook,
|
|
23
|
+
plugin
|
|
24
|
+
}));
|
|
25
|
+
/**
|
|
26
|
+
* Which plugins' hooks run, on a space's properties (for every agent in the space, wherever it runs) and on an
|
|
27
|
+
* agent's instructions (for runs with those instructions, overriding the space plugin by plugin).
|
|
28
|
+
*/
|
|
29
|
+
var SettingsAnnotation = Annotation.make({
|
|
30
|
+
id: "org.dxos.annotation.hooks",
|
|
31
|
+
schema: Schema.Record(Schema.String, Schema.Boolean)
|
|
32
|
+
});
|
|
33
|
+
/** Turns `plugin`'s hooks on or off in `target`'s settings (a space's properties or an agent's instructions). */
|
|
34
|
+
var setEnabled = (target, plugin, enabled) => {
|
|
35
|
+
Obj.update(target, (target) => {
|
|
36
|
+
const settings = Annotation.get(target, SettingsAnnotation).pipe(Option.getOrElse(() => ({})));
|
|
37
|
+
Annotation.set(target, SettingsAnnotation, {
|
|
38
|
+
...settings,
|
|
39
|
+
[plugin]: enabled
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Whether `plugin`'s hooks run when no setting names it: only if every one of them is gated by a skill, so a
|
|
45
|
+
* host that has every plugin (EDGE) runs nothing a conversation did not opt into by binding the skill.
|
|
46
|
+
*/
|
|
47
|
+
var isOnByDefault = (catalog, plugin) => catalog.every((hook) => hook.plugin !== plugin || hook.skill !== void 0);
|
|
48
|
+
/**
|
|
49
|
+
* The hooks for `event` whose plugin `space` and `instructions` leave on, given the skills bound to the
|
|
50
|
+
* conversation. Hooks run in catalog order.
|
|
51
|
+
*/
|
|
52
|
+
var resolve = ({ catalog, event, space = {}, instructions = {}, skillKeys }) => {
|
|
53
|
+
const settings = {
|
|
54
|
+
...space,
|
|
55
|
+
...instructions
|
|
56
|
+
};
|
|
57
|
+
const resolution = {
|
|
58
|
+
run: [],
|
|
59
|
+
byDefault: [],
|
|
60
|
+
inactive: [],
|
|
61
|
+
missing: Object.keys(settings).filter((plugin) => settings[plugin] && !catalog.some((hook) => hook.plugin === plugin)).sort()
|
|
62
|
+
};
|
|
63
|
+
for (const hook of catalog) {
|
|
64
|
+
const setting = settings[hook.plugin];
|
|
65
|
+
if (hook.event !== event || !(setting ?? isOnByDefault(catalog, hook.plugin))) continue;
|
|
66
|
+
if (hook.skill === void 0 || skillKeys.has(hook.skill)) {
|
|
67
|
+
resolution.run.push(hook);
|
|
68
|
+
if (setting === void 0) resolution.byDefault.push(hook.key);
|
|
69
|
+
} else if (setting !== void 0) resolution.inactive.push(hook.key);
|
|
70
|
+
}
|
|
71
|
+
return resolution;
|
|
72
|
+
};
|
|
73
|
+
/** The follow-up a hook's output asks for; anything else, including no output, asks for none. */
|
|
74
|
+
var followUp = (output) => Schema.decodeUnknownOption(Output)(output).pipe(Option.flatMap(({ followUp }) => Option.fromNullishOr(followUp)), Option.filter((text) => text.length > 0), Option.getOrUndefined);
|
|
75
|
+
//#endregion
|
|
76
|
+
export { forPlugin as a, setEnabled as c, followUp as i, Output as n, isOnByDefault as o, SettingsAnnotation as r, resolve as s, Hook_exports as t };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=chunk-Hook.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-Hook.mjs","names":[],"sources":["../../src/Hook.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport { Annotation, Obj } from '@dxos/echo';\n\nimport type * as Operation from './Operation.ts';\n\n/**\n * A lifecycle hook an agent host can run, contributed by a plugin beside its skills rather than declared on a\n * {@link Skill}, so a skill stays to the Agent Skills spec's fields. Static: a hook is code, never stored in a\n * space. Whether it runs is up to its plugin's {@link SettingsAnnotation} entry (see {@link resolve}).\n */\nexport type Definition = {\n /** Stable id the trace names the hook by, e.g. `org.dxos.hook.planning.planReminder`. */\n key: string;\n\n /** Id of the plugin that contributes the hook; settings turn hooks on and off by plugin. */\n plugin: string;\n\n /**\n * When the hook fires. `end-request` is after the model has driven a request to completion: the\n * series of agent/tool turns a prompt starts.\n */\n event: 'end-request';\n\n /** Key of a skill that must be bound to the conversation for the hook to fire; absent ⇒ every conversation. */\n skill?: string;\n\n /** Runs with the conversation in its environment; may return {@link Output}. */\n operation: Operation.Definition.Any;\n\n /** Passed as the operation's input. */\n input?: Record<string, unknown>;\n\n /**\n * Run in the background: the request settles without waiting for the hook, and the agent process\n * awaits it before it finishes. For work the user should not wait on, e.g. reviewing the turn that\n * just ended.\n */\n async?: boolean;\n};\n\n/**\n * What a hook returns. A `followUp` is queued to the agent as a synthetic prompt, so the request\n * continues instead of ending — e.g. a reminder that the plan still has open tasks.\n */\nexport const Output = Schema.Struct({\n followUp: Schema.optional(Schema.String),\n});\n\nexport type Output = Schema.Schema.Type<typeof Output>;\n\n/** A hook as a plugin declares it; the plugin adds its id when it contributes the hook ({@link forPlugin}). */\nexport type Declaration = Omit<Definition, 'plugin'>;\n\n/** `hooks` as `plugin` contributes them. */\nexport const forPlugin = (plugin: string, hooks: readonly Declaration[]): Definition[] =>\n hooks.map((hook) => ({ ...hook, plugin }));\n\n/** Plugin ids whose hooks are turned on (`true`) or off (`false`); a plugin not listed has its default. */\nexport type Settings = Readonly<Record<string, boolean>>;\n\n/**\n * Which plugins' hooks run, on a space's properties (for every agent in the space, wherever it runs) and on an\n * agent's instructions (for runs with those instructions, overriding the space plugin by plugin).\n */\nexport const SettingsAnnotation = Annotation.make({\n id: 'org.dxos.annotation.hooks',\n schema: Schema.Record(Schema.String, Schema.Boolean),\n});\n\n/** Turns `plugin`'s hooks on or off in `target`'s settings (a space's properties or an agent's instructions). */\nexport const setEnabled = (target: Obj.Unknown, plugin: string, enabled: boolean): void => {\n Obj.update(target, (target) => {\n const settings = Annotation.get(target, SettingsAnnotation).pipe(Option.getOrElse(() => ({})));\n Annotation.set(target, SettingsAnnotation, { ...settings, [plugin]: enabled });\n });\n};\n\n/**\n * Whether `plugin`'s hooks run when no setting names it: only if every one of them is gated by a skill, so a\n * host that has every plugin (EDGE) runs nothing a conversation did not opt into by binding the skill.\n */\nexport const isOnByDefault = (catalog: readonly Definition[], plugin: string): boolean =>\n catalog.every((hook) => hook.plugin !== plugin || hook.skill !== undefined);\n\n/** The hooks one request runs, and what the trace records about the rest. */\nexport type Resolution = {\n /** On, available on this host, and their skill condition holds. */\n run: Definition[];\n /** Keys of the hooks in `run` that are on by their plugin's default rather than a setting. */\n byDefault: string[];\n /** Keys of hooks a setting turns on whose skill is not bound. */\n inactive: string[];\n /** Plugins a setting turns on that contribute no hook on this host (e.g. not enabled here). */\n missing: string[];\n};\n\n/**\n * The hooks for `event` whose plugin `space` and `instructions` leave on, given the skills bound to the\n * conversation. Hooks run in catalog order.\n */\nexport const resolve = ({\n catalog,\n event,\n space = {},\n instructions = {},\n skillKeys,\n}: {\n catalog: readonly Definition[];\n event: Definition['event'];\n space?: Settings;\n instructions?: Settings;\n skillKeys: ReadonlySet<string>;\n}): Resolution => {\n const settings: Settings = { ...space, ...instructions };\n const resolution: Resolution = {\n run: [],\n byDefault: [],\n inactive: [],\n missing: Object.keys(settings)\n .filter((plugin) => settings[plugin] && !catalog.some((hook) => hook.plugin === plugin))\n .sort(),\n };\n for (const hook of catalog) {\n const setting = settings[hook.plugin];\n if (hook.event !== event || !(setting ?? isOnByDefault(catalog, hook.plugin))) {\n continue;\n }\n if (hook.skill === undefined || skillKeys.has(hook.skill)) {\n resolution.run.push(hook);\n if (setting === undefined) {\n resolution.byDefault.push(hook.key);\n }\n } else if (setting !== undefined) {\n resolution.inactive.push(hook.key);\n }\n }\n return resolution;\n};\n\n/** The follow-up a hook's output asks for; anything else, including no output, asks for none. */\nexport const followUp = (output: unknown): string | undefined =>\n Schema.decodeUnknownOption(Output)(output).pipe(\n Option.flatMap(({ followUp }) => Option.fromNullishOr(followUp)),\n Option.filter((text) => text.length > 0),\n Option.getOrUndefined,\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoDA,IAAa,SAAS,OAAO,OAAO,EAClC,UAAU,OAAO,SAAS,OAAO,MAAM,EACzC,CAAC;;AAQD,IAAa,aAAa,QAAgB,UACxC,MAAM,KAAK,UAAU;CAAE,GAAG;CAAM;AAAO,EAAE;;;;;AAS3C,IAAa,qBAAqB,WAAW,KAAK;CAChD,IAAI;CACJ,QAAQ,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO;AACrD,CAAC;;AAGD,IAAa,cAAc,QAAqB,QAAgB,YAA2B;CACzF,IAAI,OAAO,SAAS,WAAW;EAC7B,MAAM,WAAW,WAAW,IAAI,QAAQ,kBAAkB,CAAC,CAAC,KAAK,OAAO,iBAAiB,CAAC,EAAE,CAAC;EAC7F,WAAW,IAAI,QAAQ,oBAAoB;GAAE,GAAG;IAAW,SAAS;EAAQ,CAAC;CAC/E,CAAC;AACH;;;;;AAMA,IAAa,iBAAiB,SAAgC,WAC5D,QAAQ,OAAO,SAAS,KAAK,WAAW,UAAU,KAAK,UAAU,KAAA,CAAS;;;;;AAkB5E,IAAa,WAAW,EACtB,SACA,OACA,QAAQ,CAAC,GACT,eAAe,CAAC,GAChB,gBAOgB;CAChB,MAAM,WAAqB;EAAE,GAAG;EAAO,GAAG;CAAa;CACvD,MAAM,aAAyB;EAC7B,KAAK,CAAC;EACN,WAAW,CAAC;EACZ,UAAU,CAAC;EACX,SAAS,OAAO,KAAK,QAAQ,CAAC,CAC3B,QAAQ,WAAW,SAAS,WAAW,CAAC,QAAQ,MAAM,SAAS,KAAK,WAAW,MAAM,CAAC,CAAC,CACvF,KAAK;CACV;CACA,KAAK,MAAM,QAAQ,SAAS;EAC1B,MAAM,UAAU,SAAS,KAAK;EAC9B,IAAI,KAAK,UAAU,SAAS,EAAE,WAAW,cAAc,SAAS,KAAK,MAAM,IACzE;EAEF,IAAI,KAAK,UAAU,KAAA,KAAa,UAAU,IAAI,KAAK,KAAK,GAAG;GACzD,WAAW,IAAI,KAAK,IAAI;GACxB,IAAI,YAAY,KAAA,GACd,WAAW,UAAU,KAAK,KAAK,GAAG;EAEtC,OAAO,IAAI,YAAY,KAAA,GACrB,WAAW,SAAS,KAAK,KAAK,GAAG;CAErC;CACA,OAAO;AACT;;AAGA,IAAa,YAAY,WACvB,OAAO,oBAAoB,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,KACzC,OAAO,SAAS,EAAE,eAAe,OAAO,cAAc,QAAQ,CAAC,GAC/D,OAAO,QAAQ,SAAS,KAAK,SAAS,CAAC,GACvC,OAAO,cACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { r as Skill } from "./chunk-Skill.mjs";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
4
|
import { Annotation, DXN, Format, JsonSchema, Obj, Ref, Type } from "@dxos/echo";
|
|
5
5
|
import { Text } from "@dxos/schema";
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
-
import { FunctionError, FunctionNotFoundError, InvalidOperationInputError, InvalidOperationOutputError, InvokerNotInitializedError, NoHandlerError, RunAgainError } from "./errors.mjs";
|
|
2
|
+
import { FunctionError, FunctionNotFoundError, InvalidOperationInputError, InvalidOperationOutputError, InvokerNotInitializedError, NoHandlerError, OperationDeniedError, RunAgainError } from "./errors.mjs";
|
|
3
|
+
import { BaseError } from "@dxos/errors";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
3
5
|
import * as Schema from "effect/Schema";
|
|
4
6
|
import { Annotation, DXN, JsonSchema, Migration, Obj, Ref, Type } from "@dxos/echo";
|
|
5
7
|
import * as Effect from "effect/Effect";
|
|
6
|
-
import * as Option from "effect/Option";
|
|
7
8
|
import * as Cause from "effect/Cause";
|
|
8
9
|
import * as Context from "effect/Context";
|
|
9
10
|
import * as Function from "effect/Function";
|
|
@@ -15,6 +16,7 @@ import { assertArgument, invariant } from "@dxos/invariant";
|
|
|
15
16
|
import { log } from "@dxos/log";
|
|
16
17
|
//#region src/Operation.ts
|
|
17
18
|
var Operation_exports = /* @__PURE__ */ __exportAll({
|
|
19
|
+
ConsentPreviewAnnotation: () => ConsentPreviewAnnotation,
|
|
18
20
|
DefinitionTypeId: () => DefinitionTypeId,
|
|
19
21
|
DurableDefinitionTypeId: () => DurableDefinitionTypeId,
|
|
20
22
|
DurableTypeId: () => DurableTypeId,
|
|
@@ -30,34 +32,53 @@ var Operation_exports = /* @__PURE__ */ __exportAll({
|
|
|
30
32
|
NoHandlerError: () => NoHandlerError,
|
|
31
33
|
NotifyOptions: () => NotifyOptions,
|
|
32
34
|
NotifyOptionsAnnotation: () => NotifyOptionsAnnotation,
|
|
35
|
+
OperationDeniedError: () => OperationDeniedError,
|
|
33
36
|
PersistentOperation: () => PersistentOperation,
|
|
34
37
|
PersistentOperation_v0_1_0: () => PersistentOperation_v0_1_0,
|
|
38
|
+
RequiresAnnotation: () => RequiresAnnotation,
|
|
39
|
+
ScriptDefinitionTypeId: () => ScriptDefinitionTypeId,
|
|
40
|
+
ScriptDialect: () => ScriptDialect,
|
|
41
|
+
ScriptDialects: () => ScriptDialects,
|
|
42
|
+
ScriptError: () => ScriptError,
|
|
43
|
+
ScriptResult: () => ScriptResult,
|
|
44
|
+
ScriptStats: () => ScriptStats,
|
|
35
45
|
Service: () => Service,
|
|
36
46
|
VisibleAnnotation: () => VisibleAnnotation,
|
|
37
47
|
annotate: () => annotate,
|
|
38
48
|
deserialize: () => deserialize,
|
|
39
49
|
findToolNameCollisions: () => findToolNameCollisions,
|
|
50
|
+
getConsentPreview: () => getConsentPreview,
|
|
40
51
|
getKey: () => getKey,
|
|
41
52
|
getMutation: () => getMutation,
|
|
53
|
+
getRequirements: () => getRequirements,
|
|
42
54
|
getVersion: () => getVersion,
|
|
43
55
|
idempotent: () => idempotent,
|
|
56
|
+
inlineScript: () => inlineScript,
|
|
44
57
|
invoke: () => invoke,
|
|
45
58
|
isDurable: () => isDurable,
|
|
46
59
|
isDurableDefinition: () => isDurableDefinition,
|
|
47
60
|
isIdempotent: () => isIdempotent,
|
|
61
|
+
isInlineScript: () => isInlineScript,
|
|
48
62
|
isLazyHandler: () => isLazyHandler,
|
|
49
63
|
isOperationDefinition: () => isOperationDefinition,
|
|
50
64
|
isOperationWithHandler: () => isOperationWithHandler,
|
|
65
|
+
isScript: () => isScript,
|
|
66
|
+
isScriptDialect: () => isScriptDialect,
|
|
67
|
+
isScriptRef: () => isScriptRef,
|
|
51
68
|
isVisible: () => isVisible,
|
|
52
69
|
lazyHandler: () => lazyHandler,
|
|
53
70
|
make: () => make,
|
|
54
71
|
makeDurable: () => makeDurable,
|
|
72
|
+
makeScript: () => makeScript,
|
|
55
73
|
migrations: () => migrations,
|
|
56
74
|
mutation: () => mutation,
|
|
57
75
|
opaqueHandler: () => opaqueHandler,
|
|
58
76
|
prepare: () => prepare,
|
|
59
77
|
runAgain: () => runAgain,
|
|
60
78
|
schedule: () => schedule,
|
|
79
|
+
scriptDialectOf: () => scriptDialectOf,
|
|
80
|
+
scriptRef: () => scriptRef,
|
|
81
|
+
scriptRequest: () => scriptRequest,
|
|
61
82
|
serializable: () => serializable,
|
|
62
83
|
serialize: () => serialize,
|
|
63
84
|
setFrom: () => setFrom,
|
|
@@ -238,6 +259,116 @@ var sanitizeRpcs = (defined, provided) => {
|
|
|
238
259
|
return provided;
|
|
239
260
|
};
|
|
240
261
|
/**
|
|
262
|
+
* Language an inline script snippet is written in.
|
|
263
|
+
*
|
|
264
|
+
* Carried by the snippet rather than by the runtime, because one runtime serves several: a code-mode
|
|
265
|
+
* turn writes `plain` or `effect` against the same host that runs a `typescript` module.
|
|
266
|
+
*/
|
|
267
|
+
var ScriptDialect = Schema.Literals([
|
|
268
|
+
"plain",
|
|
269
|
+
"effect",
|
|
270
|
+
"javascript",
|
|
271
|
+
"typescript"
|
|
272
|
+
]);
|
|
273
|
+
/** Named {@link ScriptDialect} values, so a caller names one without spelling the literal. */
|
|
274
|
+
var ScriptDialects = {
|
|
275
|
+
/** Code-mode's plain dialect: `await`-style bindings over the workspace. */
|
|
276
|
+
Plain: "plain",
|
|
277
|
+
/** Code-mode's Effect dialect: the body of an `Effect.gen` generator. */
|
|
278
|
+
Effect: "effect",
|
|
279
|
+
JavaScript: "javascript",
|
|
280
|
+
TypeScript: "typescript"
|
|
281
|
+
};
|
|
282
|
+
/** A snippet source. */
|
|
283
|
+
var inlineScript = (code, options) => ({
|
|
284
|
+
_tag: "inline",
|
|
285
|
+
code,
|
|
286
|
+
dialect: options?.dialect ?? ScriptDialects.TypeScript
|
|
287
|
+
});
|
|
288
|
+
/** A source pointing at a `Script` object. */
|
|
289
|
+
var scriptRef = (script) => ({
|
|
290
|
+
_tag: "object",
|
|
291
|
+
script
|
|
292
|
+
});
|
|
293
|
+
var isInlineScript = (source) => source._tag === "inline";
|
|
294
|
+
var isScriptRef = (source) => source._tag === "object";
|
|
295
|
+
/**
|
|
296
|
+
* A script that could not be run: an unsupported dialect, a source that would not resolve, or a
|
|
297
|
+
* runtime with no way to run scripts at all.
|
|
298
|
+
*
|
|
299
|
+
* A failure the SCRIPT raised is not one of these — that is a {@link ScriptResult} carrying `error`,
|
|
300
|
+
* since the caller (a model writing code, a person at `dx eval`) is meant to read it and write
|
|
301
|
+
* different code rather than see the call fail.
|
|
302
|
+
*/
|
|
303
|
+
var ScriptError = class extends BaseError.extend("ScriptError", "Script could not be run") {};
|
|
304
|
+
/** The host calls one run made: how many, and the wall time spent waiting on them. */
|
|
305
|
+
var ScriptStats = Schema.Struct({
|
|
306
|
+
calls: Schema.Number,
|
|
307
|
+
callMs: Schema.Number
|
|
308
|
+
});
|
|
309
|
+
/**
|
|
310
|
+
* What a run produced: what the script printed, why it failed when it did, and the calls it made.
|
|
311
|
+
*
|
|
312
|
+
* This is a script operation's default `output`, so `Operation.invoke` on one answers with it.
|
|
313
|
+
*/
|
|
314
|
+
var ScriptResult = Schema.Struct({
|
|
315
|
+
output: Schema.String,
|
|
316
|
+
/** Present exactly when the script itself failed; `output` then holds what it printed first. */
|
|
317
|
+
error: Schema.optional(Schema.String),
|
|
318
|
+
stats: Schema.optional(ScriptStats)
|
|
319
|
+
});
|
|
320
|
+
/**
|
|
321
|
+
* The dialect a source is written in. A {@link ScriptRef} is TypeScript: a `Script` object is what the
|
|
322
|
+
* script editor writes, and it compiles TypeScript.
|
|
323
|
+
*/
|
|
324
|
+
var scriptDialectOf = (source) => isInlineScript(source) ? source.dialect : ScriptDialects.TypeScript;
|
|
325
|
+
/** The request that runs `operation` on `input`. */
|
|
326
|
+
var scriptRequest = (operation, input, options) => ({
|
|
327
|
+
...options,
|
|
328
|
+
source: operation.source,
|
|
329
|
+
...input !== void 0 ? { input } : {},
|
|
330
|
+
...operation.timeout !== void 0 ? { timeoutMs: operation.timeout } : {}
|
|
331
|
+
});
|
|
332
|
+
var ScriptDefinitionTypeId = "~@dxos/operation/ScriptDefinition";
|
|
333
|
+
/**
|
|
334
|
+
* Creates a script operation, which is invoked like any other operation.
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```ts
|
|
338
|
+
* const result = yield* Operation.invoke(
|
|
339
|
+
* Operation.makeScript({
|
|
340
|
+
* meta: { key: DXN.make('example.hello') },
|
|
341
|
+
* source: Operation.inlineScript('yield* print("hi")', { dialect: Operation.ScriptDialects.Effect }),
|
|
342
|
+
* }),
|
|
343
|
+
* undefined,
|
|
344
|
+
* { on: 'local' },
|
|
345
|
+
* );
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
var makeScript = (props) => ({
|
|
349
|
+
[DefinitionTypeId]: {},
|
|
350
|
+
[ScriptDefinitionTypeId]: {},
|
|
351
|
+
...props,
|
|
352
|
+
input: props.input ?? Schema.Unknown,
|
|
353
|
+
output: props.output ?? ScriptResult,
|
|
354
|
+
executionMode: "async",
|
|
355
|
+
types: [],
|
|
356
|
+
services: [],
|
|
357
|
+
pipe() {
|
|
358
|
+
return Pipeable.pipeArguments(this, arguments);
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
/**
|
|
362
|
+
* Whether an operation is the script kind, which a runtime runs rather than looking up a handler for.
|
|
363
|
+
*
|
|
364
|
+
* Narrows a typed definition to the script kind WITH its own input and output types, so a runtime
|
|
365
|
+
* that branches on it keeps the operation's codecs — without them the branch could only be reconciled
|
|
366
|
+
* with a cast.
|
|
367
|
+
*/
|
|
368
|
+
var isScript = (value) => typeof value === "object" && value !== null && "~@dxos/operation/ScriptDefinition" in value;
|
|
369
|
+
/** Whether `value` names a known {@link ScriptDialect}. */
|
|
370
|
+
var isScriptDialect = (value) => typeof value === "string" && ScriptDialect.literals.includes(value);
|
|
371
|
+
/**
|
|
241
372
|
* Constant namespace prefix elided from tool names; keys outside it (examples, third-party) keep every segment.
|
|
242
373
|
*/
|
|
243
374
|
var TOOL_NAME_KEY_PREFIX = "org.dxos.operation.";
|
|
@@ -265,7 +396,7 @@ var toolNameFromKey = (key) => {
|
|
|
265
396
|
invariant(TOOL_NAME_REGEXP.test(name), `Invalid tool name: ${name}`, {
|
|
266
397
|
"~LogMeta": "~LogMeta",
|
|
267
398
|
F: __dxlog_file,
|
|
268
|
-
L:
|
|
399
|
+
L: 1009,
|
|
269
400
|
S: void 0,
|
|
270
401
|
A: ["TOOL_NAME_REGEXP.test(name)", "`Invalid tool name: ${name}`"]
|
|
271
402
|
});
|
|
@@ -379,7 +510,7 @@ var serializable = (operations) => operations.flatMap((operation) => {
|
|
|
379
510
|
}, {
|
|
380
511
|
"~LogMeta": "~LogMeta",
|
|
381
512
|
F: __dxlog_file,
|
|
382
|
-
L:
|
|
513
|
+
L: 1164,
|
|
383
514
|
S: void 0
|
|
384
515
|
});
|
|
385
516
|
return [];
|
|
@@ -545,6 +676,39 @@ var isVisible = (op) => Option.getOrElse(Annotation.get(op, VisibleAnnotation),
|
|
|
545
676
|
*/
|
|
546
677
|
var idempotent = annotate(IdempotentAnnotation, true);
|
|
547
678
|
/**
|
|
679
|
+
* What an operation requires of the process that invokes it, in the vocabulary of the permission
|
|
680
|
+
* system that interprets it (`@dxos/permission` requirements). Present ⇒ the runtime refuses the
|
|
681
|
+
* call unless the invoking process holds a guard that admits it; absent ⇒ the operation is never
|
|
682
|
+
* checked, which is what keeps permissions opt-in.
|
|
683
|
+
*/
|
|
684
|
+
var RequiresAnnotation = Annotation.make({
|
|
685
|
+
id: "org.dxos.operation.requires",
|
|
686
|
+
schema: Schema.Array(Schema.Unknown)
|
|
687
|
+
});
|
|
688
|
+
/** The operation's declared requirements; empty when it declares none. */
|
|
689
|
+
var getRequirements = (op) => op.meta.annotations ? Option.getOrElse(Annotation.getDictionary(op.meta.annotations, RequiresAnnotation), () => []) : [];
|
|
690
|
+
/**
|
|
691
|
+
* The input field a consent prompt shows before the person allows the call (the body of an email it
|
|
692
|
+
* would send), so they approve what is sent and not only that something is.
|
|
693
|
+
*/
|
|
694
|
+
var ConsentPreviewAnnotation = Annotation.make({
|
|
695
|
+
id: "org.dxos.operation.consentPreview",
|
|
696
|
+
schema: Schema.Struct({
|
|
697
|
+
field: Schema.String,
|
|
698
|
+
label: Schema.String
|
|
699
|
+
})
|
|
700
|
+
});
|
|
701
|
+
/** The text a consent prompt previews for this call, when the operation names a string field to show. */
|
|
702
|
+
var getConsentPreview = (op, input) => {
|
|
703
|
+
const preview = op.meta.annotations ? Annotation.getDictionary(op.meta.annotations, ConsentPreviewAnnotation) : Option.none();
|
|
704
|
+
if (Option.isNone(preview) || input === null || typeof input !== "object") return;
|
|
705
|
+
const text = Reflect.get(input, preview.value.field);
|
|
706
|
+
return typeof text === "string" && text.trim().length > 0 ? {
|
|
707
|
+
label: preview.value.label,
|
|
708
|
+
text
|
|
709
|
+
} : void 0;
|
|
710
|
+
};
|
|
711
|
+
/**
|
|
548
712
|
* Context tag for the Operation service.
|
|
549
713
|
* Operation handlers can yield this to invoke other operations or schedule followups.
|
|
550
714
|
*
|
|
@@ -647,6 +811,6 @@ var migrations = [Migration.define({
|
|
|
647
811
|
})
|
|
648
812
|
})];
|
|
649
813
|
//#endregion
|
|
650
|
-
export {
|
|
814
|
+
export { runAgain as $, getVersion as A, isOperationWithHandler as B, annotate as C, getKey as D, getConsentPreview as E, isDurableDefinition as F, lazyHandler as G, isScriptDialect as H, isIdempotent as I, makeScript as J, make as K, isInlineScript as L, inlineScript as M, invoke as N, getMutation as O, isDurable as P, prepare as Q, isLazyHandler as R, VisibleAnnotation as S, findToolNameCollisions as T, isScriptRef as U, isScript as V, isVisible as W, mutation as X, migrations as Y, opaqueHandler as Z, ScriptDialects as _, IdempotentAnnotation as a, serialize as at, ScriptStats as b, MutationAnnotation as c, toolNameFromKey as ct, Operation_exports as d, withDurableHandler as dt, schedule as et, PersistentOperation as f, withHandler as ft, ScriptDialect as g, ScriptDefinitionTypeId as h, DurableTypeId as i, serializable as it, idempotent as j, getRequirements as k, NotifyOptions as l, tryToolNameFromKey as lt, RequiresAnnotation as m, DefinitionTypeId as n, scriptRef as nt, Label as o, setFrom as ot, PersistentOperation_v0_1_0 as p, withInvocationOptions as pt, makeDurable as q, DurableDefinitionTypeId as r, scriptRequest as rt, LazyHandlerTypeId as s, toolName as st, ConsentPreviewAnnotation as t, scriptDialectOf as tt, NotifyOptionsAnnotation as u, visible as ut, ScriptError as v, deserialize as w, Service as x, ScriptResult as y, isOperationDefinition as z };
|
|
651
815
|
|
|
652
816
|
//# sourceMappingURL=chunk-Operation.mjs.map
|