@schlenkr/ragents 0.1.14 → 0.1.16
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/apps/server/package.json +1 -1
- package/apps/server/src/api/contracts.ts +19 -1
- package/apps/server/src/api/core-methods.ts +12 -0
- package/apps/server/src/chat-handler.ts +19 -0
- package/apps/server/src/host-api.json +2 -0
- package/apps/server/src/host-api.ts +2 -2
- package/apps/server/src/plugin-build/build.ts +1 -1
- package/apps/server/src/plugin-support/actor-programs/app-project.ts +62 -18
- package/apps/server/src/plugin-support/actor-programs/client-contracts.ts +47 -8
- package/apps/server/src/plugin-support/actor-programs/contract.ts +18 -1
- package/apps/server/src/plugin-support/actor-programs/service.ts +22 -1
- package/apps/server/src/plugin-support/plugin-folder.ts +14 -1
- package/apps/server/src/plugin-support/run-scripts.ts +27 -2
- package/apps/server/src/profile/compose.ts +2 -0
- package/apps/server/src/provider.ts +23 -4
- package/apps/server/src/ragents/chat-projection.ts +7 -0
- package/apps/server/src/ragents/global-chat.ts +5 -1
- package/apps/server/src/ragents/run-script-tools.ts +66 -0
- package/apps/server/src/ragents/session.ts +122 -60
- package/apps/web/dist/assets/{highlighted-body-KPVGNVTW-BslIwn_y.js → highlighted-body-KPVGNVTW-BwD4uYEe.js} +1 -1
- package/apps/web/dist/assets/{main-BUN8m8SW.js → main-KBrc5Q77.js} +1 -1
- package/apps/web/dist/assets/{mermaid-HWGCJPDP-B1erZlFM.js → mermaid-HWGCJPDP-CSCkaArr.js} +88 -88
- package/apps/web/dist/assets/runPanel-BjG5NBKm.js +26 -0
- package/apps/web/dist/help/guide-clients.html +21 -4
- package/apps/web/dist/help/guide-clients.md +23 -4
- package/apps/web/dist/help/guide-plugins.html +12 -2
- package/apps/web/dist/help/guide-plugins.md +9 -2
- package/apps/web/dist/help/guide-programs.html +8 -2
- package/apps/web/dist/help/guide-programs.md +9 -2
- package/apps/web/dist/help/guide-runtime.html +3 -2
- package/apps/web/dist/help/guide-runtime.md +3 -2
- package/apps/web/dist/help/index.html +1 -1
- package/apps/web/dist/help/mini-app.css +7 -2
- package/apps/web/dist/host-web.json +6 -6
- package/apps/web/dist/index.html +2 -2
- package/apps/web/dist/run-panel.html +2 -2
- package/apps/web/package.json +1 -1
- package/apps/web/src/run-panel/RunPanelApp.tsx +1 -1
- package/apps/web/src/run-panel/RunPanelMenu.tsx +47 -11
- package/bundles/ragents.activity/ragents-bundle.json +1 -1
- package/bundles/ragents.actor-programs/ragents-bundle.json +4 -2
- package/bundles/ragents.actor-programs/server/index.js +437 -24
- package/bundles/ragents.actor-programs/server/index.js.map +4 -4
- package/bundles/ragents.actor-programs/web/index.js.map +1 -1
- package/bundles/ragents.ask/ragents-bundle.json +2 -2
- package/bundles/ragents.ask/server/index.js +1 -0
- package/bundles/ragents.ask/server/index.js.map +2 -2
- package/bundles/ragents.browser/ragents-bundle.json +1 -1
- package/bundles/ragents.documents/ragents-bundle.json +1 -1
- package/bundles/ragents.lsp-fsharp/ragents-bundle.json +1 -1
- package/bundles/ragents.lsp-roslyn/ragents-bundle.json +1 -1
- package/bundles/ragents.lsp-typescript/ragents-bundle.json +1 -1
- package/bundles/ragents.model-relay/ragents-bundle.json +1 -1
- package/bundles/ragents.orchestration/ragents-bundle.json +7 -4
- package/bundles/ragents.orchestration/server/chunks/chunk-QS3WJ3D7.js +11 -0
- package/bundles/ragents.orchestration/server/chunks/chunk-QS3WJ3D7.js.map +7 -0
- package/bundles/ragents.orchestration/server/exports/server/contract.js +9 -0
- package/bundles/ragents.orchestration/server/exports/server/contract.js.map +7 -0
- package/bundles/ragents.orchestration/server/index.js +49 -3
- package/bundles/ragents.orchestration/server/index.js.map +2 -2
- package/bundles/ragents.orchestration/surface.hbs +5 -0
- package/bundles/ragents.overseer/ragents-bundle.json +1 -1
- package/bundles/ragents.processes/ragents-bundle.json +1 -1
- package/bundles/ragents.product/ragents-bundle.json +1 -1
- package/bundles/ragents.profile-distribution/ragents-bundle.json +1 -1
- package/bundles/ragents.reference/actors/notebook/package.json +16 -0
- package/bundles/ragents.reference/actors/notebook/src/client.tsx +31 -0
- package/bundles/ragents.reference/actors/notebook/src/server.ts +27 -0
- package/bundles/ragents.reference/actors/notebook/tests/program.test.ts +27 -0
- package/bundles/ragents.reference/ragents-bundle.json +4 -3
- package/bundles/ragents.reference/run-scripts/quick-note/RUN.md +14 -0
- package/bundles/ragents.reference/run-scripts/quick-note/package.json +9 -0
- package/bundles/ragents.reference/run-scripts/quick-note/src/server.ts +29 -0
- package/bundles/ragents.reference/run-scripts/quick-note/tests/program.test.ts +43 -0
- package/bundles/ragents.reference/run-scripts/run-roster/RUN.md +19 -0
- package/bundles/ragents.reference/run-scripts/run-roster/package.json +9 -0
- package/bundles/ragents.reference/run-scripts/run-roster/src/server.ts +26 -0
- package/bundles/ragents.reference/run-scripts/run-roster/tests/program.test.ts +47 -0
- package/bundles/ragents.todo/ragents-bundle.json +1 -1
- package/bundles/ragents.transcript/ragents-bundle.json +1 -1
- package/bundles/ragents.watch/ragents-bundle.json +1 -1
- package/bundles/ragents.workspace/ragents-bundle.json +1 -1
- package/package.json +3 -3
- package/packages/ragents/src/domain/vocabulary.ts +4 -0
- package/packages/ragents/src/index.ts +3 -1
- package/packages/ragents/src/plugin-host.ts +62 -10
- package/packages/ragents/src/plugin-types.ts +11 -0
- package/packages/ragents/src/runtime/guards.ts +2 -1
- package/packages/ragents/src/typescript/async-compiler.ts +11 -1
- package/plugins/ragents.actor-programs/server/index.ts +3 -0
- package/plugins/ragents.actor-programs/server/runtime.ts +424 -28
- package/plugins/ragents.actor-programs/server/script-state.ts +54 -0
- package/plugins/ragents.actor-programs/server/tool-contributor.ts +2 -0
- package/plugins/ragents.ask/server/ask-tool.ts +1 -0
- package/plugins/ragents.orchestration/ragents-plugin.json +1 -0
- package/plugins/ragents.orchestration/server/contract.ts +14 -0
- package/plugins/ragents.orchestration/server/index.ts +4 -1
- package/plugins/ragents.orchestration/server/surface-tool.ts +58 -2
- package/plugins/ragents.orchestration/surface.hbs +5 -0
- package/plugins/ragents.reference/actors/notebook/package.json +16 -0
- package/plugins/ragents.reference/actors/notebook/src/client.tsx +31 -0
- package/plugins/ragents.reference/actors/notebook/src/server.ts +27 -0
- package/plugins/ragents.reference/actors/notebook/tests/program.test.ts +27 -0
- package/plugins/ragents.reference/run-scripts/quick-note/RUN.md +14 -0
- package/plugins/ragents.reference/run-scripts/quick-note/package.json +9 -0
- package/plugins/ragents.reference/run-scripts/quick-note/src/server.ts +29 -0
- package/plugins/ragents.reference/run-scripts/quick-note/tests/program.test.ts +43 -0
- package/plugins/ragents.reference/run-scripts/run-roster/RUN.md +19 -0
- package/plugins/ragents.reference/run-scripts/run-roster/package.json +9 -0
- package/plugins/ragents.reference/run-scripts/run-roster/src/server.ts +26 -0
- package/plugins/ragents.reference/run-scripts/run-roster/tests/program.test.ts +47 -0
- package/scripts/agent/agent-cli.ts +46 -2
- package/scripts/package/ragents.mjs +3 -1
- package/apps/web/dist/assets/runPanel-s8gGpr9M.js +0 -21
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../plugins/ragents.ask/server/index.ts", "../../../plugins/ragents.ask/server/answer-method.ts", "../../../plugins/ragents.ask/contract.ts", "../../../plugins/ragents.ask/server/ask-service.ts", "../../../plugins/ragents.ask/ask-payload.ts", "../../../plugins/ragents.ask/server/tool-contributor.ts", "../../../plugins/ragents.ask/server/ask-tool.ts"],
|
|
4
|
-
"sourcesContent": ["import type { RAgentsPlugin } from \"@ragents/engine\";\nimport { pluginAsset } from \"@ragents/host/plugin-support/plugin-folder.js\";\nimport type { PluginModule } from \"@ragents/host/plugin-support/plugin-module.js\";\nimport { handlebarsPrompt } from \"@ragents/host/plugin-support/prompt.js\";\nimport { runGuardToken } from \"@ragents/host/ragents/host-services.js\";\nimport { runtimeBridgeToken } from \"@ragents/host/ragents/runtime-bridge.js\";\nimport { createAnswerMethod } from \"./answer-method.js\";\nimport { RuntimeAskService } from \"./ask-service.js\";\nimport { askServiceToken } from \"./contract.js\";\nimport { createAskToolContributor } from \"./tool-contributor.js\";\n\nconst askPlugin: RAgentsPlugin = {\n manifest: { id: \"ragents.ask\" },\n register: (host) => {\n const service = new RuntimeAskService();\n host.provide(askServiceToken, service);\n host.provide(runtimeBridgeToken, { bind: (runtime) => service.bind(runtime) });\n host.prompts(handlebarsPrompt(\"ragents.ask.prompt\", 480, pluginAsset(\"ragents.ask\", \"ask.hbs\")));\n host.functions(createAskToolContributor(service));\n host.methods(createAnswerMethod(service, host.service(runGuardToken)));\n },\n};\n\nexport const plugin: PluginModule = { create: () => askPlugin };\n", "import { DomainError, implement, type MethodContribution } from \"@ragents/engine\";\nimport { askContracts } from \"../contract.js\";\nimport type { RuntimeAskService } from \"./ask-service.js\";\n\nexport const createAnswerMethod = (\n service: RuntimeAskService,\n ensureSession: (runId: string) => void,\n): MethodContribution => implement(askContracts.answer, ({ runId, actionId, answer, dismiss }) => {\n if (dismiss !== true && (typeof answer !== \"string\" || answer.trim() === \"\")) {\n throw new DomainError(\"answer-missing\", \"answer is required unless the question is dismissed\", 400);\n }\n ensureSession(runId);\n service.answer(runId, actionId, { ...(answer !== undefined ? { answer } : {}), ...(dismiss !== undefined ? { dismiss } : {}) });\n return null;\n});\n", "import { Type } from \"typebox\";\nimport { defineOperation } from \"@ragents/engine/src/rpc/contract\";\n\nexport const askContracts = {\n answer: defineOperation({\n id: \"ragents.ask.answer\",\n description: \"Answer or dismiss a question of the run. Rights: runs.read and runs.write.\",\n rights: [\"runs.read\", \"runs.write\"],\n input: Type.Object({\n runId: Type.String({ minLength: 1, maxLength: 64, description: \"Run id\" }),\n actionId: Type.String({ minLength: 1, maxLength: 80, description: \"Question id\" }),\n answer: Type.Optional(Type.String({ description: \"The user's answer\" })),\n dismiss: Type.Optional(Type.Boolean({ description: \"true dismisses the question without an answer\" })),\n }, { additionalProperties: false }),\n result: Type.Null(),\n }),\n};\n", "import { randomUUID } from \"node:crypto\";\nimport {\n DomainError,\n type Action,\n type CommandContext,\n type JournalEvent,\n type JsonValue,\n type Orchestration,\n} from \"@ragents/engine\";\nimport { askPayloadOf, ASK_PLUGIN_ID, SUPERSEDED_ANSWER, supersedingInputOf } from \"../ask-payload.js\";\nimport { DISMISSED_ANSWER, type AskCall, type AskRequest, type AskService } from \"./contract.js\";\n\nconst answerOf = (decision: \"approved\" | \"dismissed\", result: unknown): string =>\n decision !== \"approved\"\n ? supersedingInputOf(result) === undefined ? DISMISSED_ANSWER : SUPERSEDED_ANSWER\n : typeof result === \"string\" ? result : result === null || result === undefined ? \"\" : JSON.stringify(result);\n\nconst resolvedAnswerOf = (action: Action): string | null =>\n action.status === \"pending\" ? null : answerOf(action.status, action.result);\n\nconst humanInputPendingFor = (runtime: Orchestration, runId: string, actorId: string): boolean =>\n [...runtime.state(runId).inputs.values()].some((input) =>\n input.actorId === actorId && input.origin === \"human\" && input.lifecycle.kind === \"pending\");\n\ninterface Waiter {\n runId: string;\n /** The actor whose running turn waits for the answer; null for a question asked outside a turn. */\n blockedActorId: string | null;\n settle: (answer: string) => void;\n}\n\nexport class RuntimeAskService implements AskService {\n #runtime: Orchestration | undefined;\n readonly #waiters = new Map<string, Waiter>();\n readonly #aborting = new Set<string>();\n\n bind(runtime: Orchestration): void {\n if (this.#runtime) throw new Error(\"The ask service is already bound to a runtime\");\n this.#runtime = runtime;\n runtime.subscribe((events) => this.#onJournal(events));\n }\n\n ask(call: AskCall, request: AskRequest, signal: AbortSignal | undefined): Promise<string> {\n const runtime = this.#requireRuntime();\n if (call.turnId && humanInputPendingFor(runtime, call.runId, call.agentId)) return Promise.resolve(SUPERSEDED_ANSWER);\n const context: CommandContext = {\n actorId: call.agentId,\n commandId: call.commandId,\n ...(call.turnId ? { turnId: call.turnId, correlationId: call.turnId, causationId: call.turnId } : {}),\n };\n runtime.proposeAction(context, call.runId, {\n owner: ASK_PLUGIN_ID,\n title: request.question,\n description: request.description,\n parameters: request.parameters,\n input: { label: \"Answer\", placeholder: null, required: true },\n payload: {\n question: request.question,\n options: [...request.options],\n multi: request.multi === true,\n ...(request.recipient ? { recipient: request.recipient } : {}),\n },\n });\n const proposed = runtime.events(call.runId).find((event) =>\n event.type === \"action.proposed\" && event.commandId === call.commandId);\n if (proposed?.type !== \"action.proposed\") {\n throw new Error(`The question from ${call.agentId} was not created in the journal of ${call.runId}`);\n }\n return this.#awaitAnswer(call.runId, proposed.payload.actionId, call.turnId ? call.agentId : null, signal);\n }\n\n answer(runId: string, actionId: string, input: { answer?: string; dismiss?: boolean }): void {\n const runtime = this.#requireRuntime();\n const state = runtime.state(runId);\n const action = state.actions.get(actionId);\n if (!action || action.owner !== ASK_PLUGIN_ID) {\n throw new DomainError(\"question-not-found\", `Question ${actionId} does not exist in run ${runId}.`, 404);\n }\n runtime.resolveAction(\n { actorId: state.ownerId, commandId: `ask-answer:${actionId}:${randomUUID()}` },\n runId,\n actionId,\n input.dismiss === true\n ? { decision: \"dismissed\", result: null }\n : { decision: \"approved\", result: input.answer ?? null },\n );\n }\n\n withdraw(runId: string, actionId: string): void {\n this.#dismiss(runId, actionId, \"ask-withdraw\", null, DISMISSED_ANSWER);\n }\n\n #supersede(runId: string, actionId: string, inputId: string): void {\n try {\n this.#dismiss(runId, actionId, \"ask-supersede\", { supersededBy: inputId }, SUPERSEDED_ANSWER);\n } catch (error) {\n console.error(`Question ${actionId} could not be closed for message ${inputId}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n #dismiss(runId: string, actionId: string, commandPrefix: string, result: JsonValue, answer: string): void {\n const runtime = this.#requireRuntime();\n const state = runtime.state(runId);\n const action = state.actions.get(actionId);\n if (action?.owner !== ASK_PLUGIN_ID || action.status !== \"pending\") return;\n this.#aborting.add(actionId);\n try {\n runtime.resolveAction(\n { actorId: state.ownerId, commandId: `${commandPrefix}:${actionId}:${randomUUID()}` },\n runId,\n actionId,\n { decision: \"dismissed\", result },\n );\n } finally {\n this.#aborting.delete(actionId);\n }\n this.#waiters.get(actionId)?.settle(answer);\n }\n\n #awaitAnswer(runId: string, actionId: string, blockedActorId: string | null, signal: AbortSignal | undefined): Promise<string> {\n const runtime = this.#requireRuntime();\n const action = runtime.state(runId).actions.get(actionId);\n if (!action) throw new Error(`Question ${actionId} does not exist in run ${runId}`);\n const settled = resolvedAnswerOf(action);\n if (settled !== null) return Promise.resolve(settled);\n return new Promise<string>((resolve, reject) => {\n const abort = () => {\n this.#waiters.delete(actionId);\n this.#aborting.add(actionId);\n try {\n const state = runtime.state(runId);\n const pending = state.actions.get(actionId);\n if (pending?.status === \"pending\") {\n runtime.resolveAction(\n { actorId: state.ownerId, commandId: `ask-abort:${actionId}:${randomUUID()}` },\n runId,\n actionId,\n { decision: \"dismissed\", result: null },\n );\n }\n reject(new Error(\"Waiting for the answer was cancelled.\"));\n } catch (error) {\n reject(error);\n } finally {\n this.#aborting.delete(actionId);\n }\n };\n if (signal?.aborted) {\n abort();\n return;\n }\n signal?.addEventListener(\"abort\", abort, { once: true });\n this.#waiters.set(actionId, {\n runId,\n blockedActorId,\n settle: (answer) => {\n signal?.removeEventListener(\"abort\", abort);\n this.#waiters.delete(actionId);\n resolve(answer);\n },\n });\n });\n }\n\n #onJournal(events: JournalEvent[]): void {\n for (const event of events) {\n if (event.type === \"actor.input.enqueued\") {\n if (event.payload.origin !== \"human\") continue;\n const { actorId, inputId } = event.payload;\n for (const [actionId, waiter] of this.#waiters) {\n if (waiter.runId !== event.runId || waiter.blockedActorId !== actorId) continue;\n queueMicrotask(() => this.#supersede(event.runId, actionId, inputId));\n }\n continue;\n }\n if (event.type !== \"action.resolved\") continue;\n if (this.#aborting.has(event.payload.actionId)) continue;\n const resolved = this.#requireRuntime().state(event.runId).actions.get(event.payload.actionId);\n if (resolved?.owner !== ASK_PLUGIN_ID) continue;\n const answer = answerOf(event.payload.decision, event.payload.result);\n const waiter = this.#waiters.get(event.payload.actionId);\n if (waiter) {\n waiter.settle(answer);\n continue;\n }\n queueMicrotask(() => this.#enqueueAnswer(event.runId, event.payload.actionId, answer));\n }\n }\n\n #enqueueAnswer(runId: string, actionId: string, answer: string): void {\n try {\n const runtime = this.#requireRuntime();\n const state = runtime.state(runId);\n const action = state.actions.get(actionId);\n if (!action) return;\n const recipientId = askPayloadOf(action.payload)?.recipient ?? action.askedBy;\n const recipient = state.actors.get(recipientId);\n if (!recipient || recipient.kind === \"human\" || recipient.lifecycle.kind === \"stopped\") return;\n runtime.enqueueInput(\n { actorId: state.ownerId, commandId: `ask-input:${actionId}` },\n runId,\n {\n actorId: recipientId,\n content: `Answer to ${recipientId === action.askedBy ? \"your question\" : \"the question\"}: ${action.title}\\nAnswer: ${answer}`,\n },\n );\n } catch (error) {\n console.error(`Answer to question ${actionId} could not be enqueued as input: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n #requireRuntime(): Orchestration {\n if (!this.#runtime) throw new Error(\"The ask service is not bound to the runtime yet\");\n return this.#runtime;\n }\n}\n", "export const ASK_PLUGIN_ID = \"ragents.ask\";\n\n/** What the asking tool call gets when a person's message to the asker closes its question. */\nexport const SUPERSEDED_ANSWER = \"Not answered: the user sent a new message instead.\";\n\nexport interface AskPayload {\n question: string;\n options: string[];\n multi: boolean;\n /** The actor the question stands for when the run owner asks it outside a turn. */\n recipient?: string;\n}\n\nconst stringArrayOf = (value: unknown): string[] | undefined =>\n Array.isArray(value) && value.every((entry) => typeof entry === \"string\") ? [...value] : undefined;\n\nexport const askPayloadOf = (payload: unknown): AskPayload | undefined => {\n if (typeof payload !== \"object\" || payload === null) return undefined;\n const candidate = payload as Partial<AskPayload>;\n const options = stringArrayOf(candidate.options);\n if (typeof candidate.question !== \"string\" || !options) return undefined;\n return {\n question: candidate.question,\n options,\n multi: candidate.multi === true,\n ...(typeof candidate.recipient === \"string\" ? { recipient: candidate.recipient } : {}),\n };\n};\n\nexport const supersedingInputOf = (result: unknown): string | undefined => {\n if (typeof result !== \"object\" || result === null) return undefined;\n const { supersededBy } = result as { supersededBy?: unknown };\n return typeof supersededBy === \"string\" ? supersededBy : undefined;\n};\n", "import type { ToolContributor } from \"@ragents/engine\";\nimport { toolDescriptorFrom } from \"@ragents/host/plugin-support/agent-tool.js\";\nimport { facesOperator } from \"@ragents/host/plugin-support/tool-availability.js\";\nimport { askToolMetadata, createAskTool } from \"./ask-tool.js\";\nimport type { AskService } from \"./contract.js\";\n\nexport const createAskToolContributor = (service: AskService): ToolContributor => ({\n name: \"ragents.ask\",\n descriptors: [toolDescriptorFrom(askToolMetadata, facesOperator)],\n tools: () => [createAskTool(service)],\n});\n", "import { Type } from \"typebox\";\nimport { defineRunFunction, type RunFunction } from \"@ragents/engine\";\nimport { facesOperator } from \"@ragents/host/plugin-support/tool-availability.js\";\nimport type { AskService } from \"./contract.js\";\n\nexport const askToolMetadata = {\n name: \"ask_user\",\n label: \"Question\",\n description: \"Asks the user for a required decision with answer options and waits for the answer.\",\n longDescription: \"Always use this tool when you need a decision from the user \"\n + \"(e.g. choosing a branch or a time range), instead of only asking the question as text. \"\n + \"With multi=true the user may choose several options; the answer is then joined with '; '. \"\n + \"Instead of choosing an option, the user can always answer freely - so expect \"\n + \"the answer to be arbitrary text.\",\n} as const;\n\nexport const createAskTool = (service: AskService): RunFunction =>\n defineRunFunction({\n ...askToolMetadata,\n schema: Type.Object({\n question: Type.String({ description: \"The question to the user, short and concrete\" }),\n options: Type.Array(Type.String(), { description: \"Answer options (2 to 6)\" }),\n multi: Type.Optional(Type.Boolean({ description: \"true = multiple choice allowed\" })),\n }),\n resultSchema: Type.String(),\n available: facesOperator,\n executionMode: \"sequential\",\n run: (scope, toolCallId, input) =>\n service.ask(\n {\n runId: scope.caller.runId,\n agentId: scope.caller.actorId,\n turnId: scope.caller.turnId,\n commandId: scope.context(toolCallId).commandId,\n },\n { question: input.question, options: input.options, multi: input.multi === true },\n scope.signal,\n ),\n });\n"],
|
|
5
|
-
"mappings": ";;;;;;;;AACA,SAAS,mBAAmB;AAE5B,SAAS,wBAAwB;AACjC,SA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,eAAe;AAAA,EACf,KAAK,CAAC,OAAO,YAAY,UACvB,QAAQ;AAAA,IACN;AAAA,MACE,OAAO,MAAM,OAAO;AAAA,MACpB,SAAS,MAAM,OAAO;AAAA,MACtB,QAAQ,MAAM,OAAO;AAAA,MACrB,WAAW,MAAM,QAAQ,UAAU,EAAE;AAAA,IACvC;AAAA,IACA,EAAE,UAAU,MAAM,UAAU,SAAS,MAAM,SAAS,OAAO,MAAM,UAAU,KAAK;AAAA,IAChF,MAAM;AAAA,EACR;AACJ,CAAC;;;
|
|
4
|
+
"sourcesContent": ["import type { RAgentsPlugin } from \"@ragents/engine\";\nimport { pluginAsset } from \"@ragents/host/plugin-support/plugin-folder.js\";\nimport type { PluginModule } from \"@ragents/host/plugin-support/plugin-module.js\";\nimport { handlebarsPrompt } from \"@ragents/host/plugin-support/prompt.js\";\nimport { runGuardToken } from \"@ragents/host/ragents/host-services.js\";\nimport { runtimeBridgeToken } from \"@ragents/host/ragents/runtime-bridge.js\";\nimport { createAnswerMethod } from \"./answer-method.js\";\nimport { RuntimeAskService } from \"./ask-service.js\";\nimport { askServiceToken } from \"./contract.js\";\nimport { createAskToolContributor } from \"./tool-contributor.js\";\n\nconst askPlugin: RAgentsPlugin = {\n manifest: { id: \"ragents.ask\" },\n register: (host) => {\n const service = new RuntimeAskService();\n host.provide(askServiceToken, service);\n host.provide(runtimeBridgeToken, { bind: (runtime) => service.bind(runtime) });\n host.prompts(handlebarsPrompt(\"ragents.ask.prompt\", 480, pluginAsset(\"ragents.ask\", \"ask.hbs\")));\n host.functions(createAskToolContributor(service));\n host.methods(createAnswerMethod(service, host.service(runGuardToken)));\n },\n};\n\nexport const plugin: PluginModule = { create: () => askPlugin };\n", "import { DomainError, implement, type MethodContribution } from \"@ragents/engine\";\nimport { askContracts } from \"../contract.js\";\nimport type { RuntimeAskService } from \"./ask-service.js\";\n\nexport const createAnswerMethod = (\n service: RuntimeAskService,\n ensureSession: (runId: string) => void,\n): MethodContribution => implement(askContracts.answer, ({ runId, actionId, answer, dismiss }) => {\n if (dismiss !== true && (typeof answer !== \"string\" || answer.trim() === \"\")) {\n throw new DomainError(\"answer-missing\", \"answer is required unless the question is dismissed\", 400);\n }\n ensureSession(runId);\n service.answer(runId, actionId, { ...(answer !== undefined ? { answer } : {}), ...(dismiss !== undefined ? { dismiss } : {}) });\n return null;\n});\n", "import { Type } from \"typebox\";\nimport { defineOperation } from \"@ragents/engine/src/rpc/contract\";\n\nexport const askContracts = {\n answer: defineOperation({\n id: \"ragents.ask.answer\",\n description: \"Answer or dismiss a question of the run. Rights: runs.read and runs.write.\",\n rights: [\"runs.read\", \"runs.write\"],\n input: Type.Object({\n runId: Type.String({ minLength: 1, maxLength: 64, description: \"Run id\" }),\n actionId: Type.String({ minLength: 1, maxLength: 80, description: \"Question id\" }),\n answer: Type.Optional(Type.String({ description: \"The user's answer\" })),\n dismiss: Type.Optional(Type.Boolean({ description: \"true dismisses the question without an answer\" })),\n }, { additionalProperties: false }),\n result: Type.Null(),\n }),\n};\n", "import { randomUUID } from \"node:crypto\";\nimport {\n DomainError,\n type Action,\n type CommandContext,\n type JournalEvent,\n type JsonValue,\n type Orchestration,\n} from \"@ragents/engine\";\nimport { askPayloadOf, ASK_PLUGIN_ID, SUPERSEDED_ANSWER, supersedingInputOf } from \"../ask-payload.js\";\nimport { DISMISSED_ANSWER, type AskCall, type AskRequest, type AskService } from \"./contract.js\";\n\nconst answerOf = (decision: \"approved\" | \"dismissed\", result: unknown): string =>\n decision !== \"approved\"\n ? supersedingInputOf(result) === undefined ? DISMISSED_ANSWER : SUPERSEDED_ANSWER\n : typeof result === \"string\" ? result : result === null || result === undefined ? \"\" : JSON.stringify(result);\n\nconst resolvedAnswerOf = (action: Action): string | null =>\n action.status === \"pending\" ? null : answerOf(action.status, action.result);\n\nconst humanInputPendingFor = (runtime: Orchestration, runId: string, actorId: string): boolean =>\n [...runtime.state(runId).inputs.values()].some((input) =>\n input.actorId === actorId && input.origin === \"human\" && input.lifecycle.kind === \"pending\");\n\ninterface Waiter {\n runId: string;\n /** The actor whose running turn waits for the answer; null for a question asked outside a turn. */\n blockedActorId: string | null;\n settle: (answer: string) => void;\n}\n\nexport class RuntimeAskService implements AskService {\n #runtime: Orchestration | undefined;\n readonly #waiters = new Map<string, Waiter>();\n readonly #aborting = new Set<string>();\n\n bind(runtime: Orchestration): void {\n if (this.#runtime) throw new Error(\"The ask service is already bound to a runtime\");\n this.#runtime = runtime;\n runtime.subscribe((events) => this.#onJournal(events));\n }\n\n ask(call: AskCall, request: AskRequest, signal: AbortSignal | undefined): Promise<string> {\n const runtime = this.#requireRuntime();\n if (call.turnId && humanInputPendingFor(runtime, call.runId, call.agentId)) return Promise.resolve(SUPERSEDED_ANSWER);\n const context: CommandContext = {\n actorId: call.agentId,\n commandId: call.commandId,\n ...(call.turnId ? { turnId: call.turnId, correlationId: call.turnId, causationId: call.turnId } : {}),\n };\n runtime.proposeAction(context, call.runId, {\n owner: ASK_PLUGIN_ID,\n title: request.question,\n description: request.description,\n parameters: request.parameters,\n input: { label: \"Answer\", placeholder: null, required: true },\n payload: {\n question: request.question,\n options: [...request.options],\n multi: request.multi === true,\n ...(request.recipient ? { recipient: request.recipient } : {}),\n },\n });\n const proposed = runtime.events(call.runId).find((event) =>\n event.type === \"action.proposed\" && event.commandId === call.commandId);\n if (proposed?.type !== \"action.proposed\") {\n throw new Error(`The question from ${call.agentId} was not created in the journal of ${call.runId}`);\n }\n return this.#awaitAnswer(call.runId, proposed.payload.actionId, call.turnId ? call.agentId : null, signal);\n }\n\n answer(runId: string, actionId: string, input: { answer?: string; dismiss?: boolean }): void {\n const runtime = this.#requireRuntime();\n const state = runtime.state(runId);\n const action = state.actions.get(actionId);\n if (!action || action.owner !== ASK_PLUGIN_ID) {\n throw new DomainError(\"question-not-found\", `Question ${actionId} does not exist in run ${runId}.`, 404);\n }\n runtime.resolveAction(\n { actorId: state.ownerId, commandId: `ask-answer:${actionId}:${randomUUID()}` },\n runId,\n actionId,\n input.dismiss === true\n ? { decision: \"dismissed\", result: null }\n : { decision: \"approved\", result: input.answer ?? null },\n );\n }\n\n withdraw(runId: string, actionId: string): void {\n this.#dismiss(runId, actionId, \"ask-withdraw\", null, DISMISSED_ANSWER);\n }\n\n #supersede(runId: string, actionId: string, inputId: string): void {\n try {\n this.#dismiss(runId, actionId, \"ask-supersede\", { supersededBy: inputId }, SUPERSEDED_ANSWER);\n } catch (error) {\n console.error(`Question ${actionId} could not be closed for message ${inputId}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n #dismiss(runId: string, actionId: string, commandPrefix: string, result: JsonValue, answer: string): void {\n const runtime = this.#requireRuntime();\n const state = runtime.state(runId);\n const action = state.actions.get(actionId);\n if (action?.owner !== ASK_PLUGIN_ID || action.status !== \"pending\") return;\n this.#aborting.add(actionId);\n try {\n runtime.resolveAction(\n { actorId: state.ownerId, commandId: `${commandPrefix}:${actionId}:${randomUUID()}` },\n runId,\n actionId,\n { decision: \"dismissed\", result },\n );\n } finally {\n this.#aborting.delete(actionId);\n }\n this.#waiters.get(actionId)?.settle(answer);\n }\n\n #awaitAnswer(runId: string, actionId: string, blockedActorId: string | null, signal: AbortSignal | undefined): Promise<string> {\n const runtime = this.#requireRuntime();\n const action = runtime.state(runId).actions.get(actionId);\n if (!action) throw new Error(`Question ${actionId} does not exist in run ${runId}`);\n const settled = resolvedAnswerOf(action);\n if (settled !== null) return Promise.resolve(settled);\n return new Promise<string>((resolve, reject) => {\n const abort = () => {\n this.#waiters.delete(actionId);\n this.#aborting.add(actionId);\n try {\n const state = runtime.state(runId);\n const pending = state.actions.get(actionId);\n if (pending?.status === \"pending\") {\n runtime.resolveAction(\n { actorId: state.ownerId, commandId: `ask-abort:${actionId}:${randomUUID()}` },\n runId,\n actionId,\n { decision: \"dismissed\", result: null },\n );\n }\n reject(new Error(\"Waiting for the answer was cancelled.\"));\n } catch (error) {\n reject(error);\n } finally {\n this.#aborting.delete(actionId);\n }\n };\n if (signal?.aborted) {\n abort();\n return;\n }\n signal?.addEventListener(\"abort\", abort, { once: true });\n this.#waiters.set(actionId, {\n runId,\n blockedActorId,\n settle: (answer) => {\n signal?.removeEventListener(\"abort\", abort);\n this.#waiters.delete(actionId);\n resolve(answer);\n },\n });\n });\n }\n\n #onJournal(events: JournalEvent[]): void {\n for (const event of events) {\n if (event.type === \"actor.input.enqueued\") {\n if (event.payload.origin !== \"human\") continue;\n const { actorId, inputId } = event.payload;\n for (const [actionId, waiter] of this.#waiters) {\n if (waiter.runId !== event.runId || waiter.blockedActorId !== actorId) continue;\n queueMicrotask(() => this.#supersede(event.runId, actionId, inputId));\n }\n continue;\n }\n if (event.type !== \"action.resolved\") continue;\n if (this.#aborting.has(event.payload.actionId)) continue;\n const resolved = this.#requireRuntime().state(event.runId).actions.get(event.payload.actionId);\n if (resolved?.owner !== ASK_PLUGIN_ID) continue;\n const answer = answerOf(event.payload.decision, event.payload.result);\n const waiter = this.#waiters.get(event.payload.actionId);\n if (waiter) {\n waiter.settle(answer);\n continue;\n }\n queueMicrotask(() => this.#enqueueAnswer(event.runId, event.payload.actionId, answer));\n }\n }\n\n #enqueueAnswer(runId: string, actionId: string, answer: string): void {\n try {\n const runtime = this.#requireRuntime();\n const state = runtime.state(runId);\n const action = state.actions.get(actionId);\n if (!action) return;\n const recipientId = askPayloadOf(action.payload)?.recipient ?? action.askedBy;\n const recipient = state.actors.get(recipientId);\n if (!recipient || recipient.kind === \"human\" || recipient.lifecycle.kind === \"stopped\") return;\n runtime.enqueueInput(\n { actorId: state.ownerId, commandId: `ask-input:${actionId}` },\n runId,\n {\n actorId: recipientId,\n content: `Answer to ${recipientId === action.askedBy ? \"your question\" : \"the question\"}: ${action.title}\\nAnswer: ${answer}`,\n },\n );\n } catch (error) {\n console.error(`Answer to question ${actionId} could not be enqueued as input: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n\n #requireRuntime(): Orchestration {\n if (!this.#runtime) throw new Error(\"The ask service is not bound to the runtime yet\");\n return this.#runtime;\n }\n}\n", "export const ASK_PLUGIN_ID = \"ragents.ask\";\n\n/** What the asking tool call gets when a person's message to the asker closes its question. */\nexport const SUPERSEDED_ANSWER = \"Not answered: the user sent a new message instead.\";\n\nexport interface AskPayload {\n question: string;\n options: string[];\n multi: boolean;\n /** The actor the question stands for when the run owner asks it outside a turn. */\n recipient?: string;\n}\n\nconst stringArrayOf = (value: unknown): string[] | undefined =>\n Array.isArray(value) && value.every((entry) => typeof entry === \"string\") ? [...value] : undefined;\n\nexport const askPayloadOf = (payload: unknown): AskPayload | undefined => {\n if (typeof payload !== \"object\" || payload === null) return undefined;\n const candidate = payload as Partial<AskPayload>;\n const options = stringArrayOf(candidate.options);\n if (typeof candidate.question !== \"string\" || !options) return undefined;\n return {\n question: candidate.question,\n options,\n multi: candidate.multi === true,\n ...(typeof candidate.recipient === \"string\" ? { recipient: candidate.recipient } : {}),\n };\n};\n\nexport const supersedingInputOf = (result: unknown): string | undefined => {\n if (typeof result !== \"object\" || result === null) return undefined;\n const { supersededBy } = result as { supersededBy?: unknown };\n return typeof supersededBy === \"string\" ? supersededBy : undefined;\n};\n", "import type { ToolContributor } from \"@ragents/engine\";\nimport { toolDescriptorFrom } from \"@ragents/host/plugin-support/agent-tool.js\";\nimport { facesOperator } from \"@ragents/host/plugin-support/tool-availability.js\";\nimport { askToolMetadata, createAskTool } from \"./ask-tool.js\";\nimport type { AskService } from \"./contract.js\";\n\nexport const createAskToolContributor = (service: AskService): ToolContributor => ({\n name: \"ragents.ask\",\n descriptors: [toolDescriptorFrom(askToolMetadata, facesOperator)],\n tools: () => [createAskTool(service)],\n});\n", "import { Type } from \"typebox\";\nimport { defineRunFunction, type RunFunction } from \"@ragents/engine\";\nimport { facesOperator } from \"@ragents/host/plugin-support/tool-availability.js\";\nimport type { AskService } from \"./contract.js\";\n\nexport const askToolMetadata = {\n name: \"ask_user\",\n label: \"Question\",\n nativeTool: true,\n description: \"Asks the user for a required decision with answer options and waits for the answer.\",\n longDescription: \"Always use this tool when you need a decision from the user \"\n + \"(e.g. choosing a branch or a time range), instead of only asking the question as text. \"\n + \"With multi=true the user may choose several options; the answer is then joined with '; '. \"\n + \"Instead of choosing an option, the user can always answer freely - so expect \"\n + \"the answer to be arbitrary text.\",\n} as const;\n\nexport const createAskTool = (service: AskService): RunFunction =>\n defineRunFunction({\n ...askToolMetadata,\n schema: Type.Object({\n question: Type.String({ description: \"The question to the user, short and concrete\" }),\n options: Type.Array(Type.String(), { description: \"Answer options (2 to 6)\" }),\n multi: Type.Optional(Type.Boolean({ description: \"true = multiple choice allowed\" })),\n }),\n resultSchema: Type.String(),\n available: facesOperator,\n executionMode: \"sequential\",\n run: (scope, toolCallId, input) =>\n service.ask(\n {\n runId: scope.caller.runId,\n agentId: scope.caller.actorId,\n turnId: scope.caller.turnId,\n commandId: scope.context(toolCallId).commandId,\n },\n { question: input.question, options: input.options, multi: input.multi === true },\n scope.signal,\n ),\n });\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AACA,SAAS,mBAAmB;AAE5B,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;;;ACLnC,SAAS,aAAa,iBAA0C;;;ACAhE,SAAS,YAAY;AACrB,SAAS,uBAAuB;AAEzB,IAAM,eAAe;AAAA,EAC1B,QAAQ,gBAAgB;AAAA,IACtB,IAAI;AAAA,IACJ,aAAa;AAAA,IACb,QAAQ,CAAC,aAAa,YAAY;AAAA,IAClC,OAAO,KAAK,OAAO;AAAA,MACjB,OAAO,KAAK,OAAO,EAAE,WAAW,GAAG,WAAW,IAAI,aAAa,SAAS,CAAC;AAAA,MACzE,UAAU,KAAK,OAAO,EAAE,WAAW,GAAG,WAAW,IAAI,aAAa,cAAc,CAAC;AAAA,MACjF,QAAQ,KAAK,SAAS,KAAK,OAAO,EAAE,aAAa,oBAAoB,CAAC,CAAC;AAAA,MACvE,SAAS,KAAK,SAAS,KAAK,QAAQ,EAAE,aAAa,gDAAgD,CAAC,CAAC;AAAA,IACvG,GA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9B,UAAU,CAAC,SAAS;AAClB,UAAM,UAAU,IAAI,kBAAkB;AACtC,SAAK,QAAQ,iBAAiB,OAAO;AACrC,SAAK,QAAQ,oBAAoB,EAAE,MAAM,CAAC,YAAY,QAAQ,KAAK,OAAO,EAAE,CAAC;AAC7E,SAAK,QAAQ,iBAAiB,sBAAsB,KAAK,YAAY,eAAe,SAAS,CAAC,CAAC;AAC/F,SAAK,UAAU,yBAAyB,OAAO,CAAC;AAChD,SAAK,QAAQ,mBAAmB,SAAS,KAAK,QAAQ,aAAa,CAAC,CAAC;AAAA,EACvE;AACF;AAEO,IAAM,SAAuB,EAAE,QAAQ,MAAM,UAAU;",
|
|
6
6
|
"names": ["DomainError", "DomainError", "waiter", "facesOperator", "Type", "facesOperator"]
|
|
7
7
|
}
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"web": {}
|
|
33
33
|
},
|
|
34
34
|
"revision": "333c6a9b57576a4ab95556e201da67ed864acdf02787ce5edbd653e7beba6020",
|
|
35
|
-
"sourceRevision": "
|
|
35
|
+
"sourceRevision": "6c3246a05b9b6ddc46373f88bca9113a2b1705487b4de41711be7f5ccb5617f3",
|
|
36
36
|
"server": "server/index.js",
|
|
37
37
|
"executor": "executor/index.mjs",
|
|
38
38
|
"exports": {
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
}
|
|
102
102
|
},
|
|
103
103
|
"revision": "3fdba8c39f30027176229901cf731b778170f0e1597c287ad94f7e48a430b5e8",
|
|
104
|
-
"sourceRevision": "
|
|
104
|
+
"sourceRevision": "8875b59b406fa0e663b9f69dff1f6525bff867dca5947d3e114084650393ebf2",
|
|
105
105
|
"server": "server/index.js",
|
|
106
106
|
"web": {
|
|
107
107
|
"entry": "web/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"revision": "a39dafc264c6703d9481f358b21e5bf3997dc5d2dc7fe0d969d4905d49c7a1f8",
|
|
32
|
-
"sourceRevision": "
|
|
32
|
+
"sourceRevision": "4ff8724bbc7065832b907cfc53ea561fa4df3e8802f2937e0df6963840baba31",
|
|
33
33
|
"server": "server/index.js",
|
|
34
34
|
"web": {
|
|
35
35
|
"entry": "web/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"revision": "cbe81aa88a4ea56476537fabbbb0995d09ccbfa269dd6a003df50a57c8286b02",
|
|
44
|
-
"sourceRevision": "
|
|
44
|
+
"sourceRevision": "0bb27e39ad643657c464d5c3c28d045ed71c2164dea8e76c4c0ffe491a84442a",
|
|
45
45
|
"server": "server/index.js",
|
|
46
46
|
"web": {
|
|
47
47
|
"entry": "web/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"revision": "8387de707a4fe8fdb8c67315346522b331728f8adf51a7fadda8db662681f0c4",
|
|
21
|
-
"sourceRevision": "
|
|
21
|
+
"sourceRevision": "9b9bdd5a6858ef808ae2541fefb7cb0262e4bc963cfb0674166ff9a29da22c5c",
|
|
22
22
|
"server": "server/index.js",
|
|
23
23
|
"web": {
|
|
24
24
|
"entry": "web/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"web": {}
|
|
27
27
|
},
|
|
28
28
|
"revision": "9090692eca49235944f149b25dccdc986a3c638007d8da2fb35f74d942454379",
|
|
29
|
-
"sourceRevision": "
|
|
29
|
+
"sourceRevision": "9548157817cee5c693da03f3a7e0f37e1099915826ef682cb0339a32736b70ef",
|
|
30
30
|
"server": "server/index.js",
|
|
31
31
|
"exports": {
|
|
32
32
|
"server": {},
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"defineToolAvailability",
|
|
14
14
|
"enqueueActorInput",
|
|
15
15
|
"eventResultSchemaOf",
|
|
16
|
-
"holdsUsable"
|
|
16
|
+
"holdsUsable",
|
|
17
|
+
"serviceToken"
|
|
17
18
|
],
|
|
18
19
|
"@ragents/engine/src/http/contracts": [
|
|
19
20
|
"handleKey"
|
|
@@ -171,15 +172,17 @@
|
|
|
171
172
|
]
|
|
172
173
|
}
|
|
173
174
|
},
|
|
174
|
-
"revision": "
|
|
175
|
-
"sourceRevision": "
|
|
175
|
+
"revision": "cbd72b88af0c8ac76486b4c0617545fc53b23315cf93dd924631ceb8e389b34b",
|
|
176
|
+
"sourceRevision": "306e4ba17b1cae6ee69a03bf8dd492a61b51eccc426b68bb55ab9b6721f08e0c",
|
|
176
177
|
"server": "server/index.js",
|
|
177
178
|
"web": {
|
|
178
179
|
"entry": "web/index.js",
|
|
179
180
|
"classes": "web/classes.json"
|
|
180
181
|
},
|
|
181
182
|
"exports": {
|
|
182
|
-
"server": {
|
|
183
|
+
"server": {
|
|
184
|
+
"server/contract": "server/exports/server/contract.js"
|
|
185
|
+
},
|
|
183
186
|
"web": {
|
|
184
187
|
"web/surface-entities": "web/exports/web/surface-entities.js",
|
|
185
188
|
"web/program-slot": "web/exports/web/program-slot.js",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createRequire as __ragentsCreateRequire } from "node:module";
|
|
2
|
+
const require = __ragentsCreateRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// server/contract.ts
|
|
5
|
+
import { serviceToken } from "@ragents/engine";
|
|
6
|
+
var surfacePlacementToken = serviceToken("ragents.orchestration.surface-placement");
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
surfacePlacementToken
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=chunk-QS3WJ3D7.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../plugins/ragents.orchestration/server/contract.ts"],
|
|
4
|
+
"sourcesContent": ["import { serviceToken, type CommandContext, type ServiceToken } from \"@ragents/engine\";\n\nexport interface SurfacePlacementRequest {\n entity: string;\n direction?: \"horizontal\" | \"vertical\";\n weight?: number;\n}\n\n/** Places an entity next to a run's surface layout, as canvas_layout_place does; an entity the layout shows already stays. */\nexport interface SurfacePlacement {\n place: (context: CommandContext, runId: string, request: SurfacePlacementRequest) => { placed: boolean };\n}\n\nexport const surfacePlacementToken: ServiceToken<SurfacePlacement> = serviceToken(\"ragents.orchestration.surface-placement\");\n"],
|
|
5
|
+
"mappings": ";;;;AAAA,SAAS,oBAA4D;AAa9D,IAAM,wBAAwD,aAAa,yCAAyC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createRequire as __ragentsCreateRequire } from "node:module";
|
|
2
|
+
const require = __ragentsCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
surfacePlacementToken
|
|
5
|
+
} from "../../chunks/chunk-QS3WJ3D7.js";
|
|
6
|
+
export {
|
|
7
|
+
surfacePlacementToken
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createRequire as __ragentsCreateRequire } from "node:module";
|
|
2
2
|
const require = __ragentsCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
surfacePlacementToken
|
|
5
|
+
} from "./chunks/chunk-QS3WJ3D7.js";
|
|
3
6
|
|
|
4
7
|
// server/index.ts
|
|
5
8
|
import {
|
|
@@ -106,6 +109,12 @@ var surfaceToolMetadata = {
|
|
|
106
109
|
description: "Arrange actors and mini-apps as tiles on the viewport-filling work surface, using a binary tree of weighted splits.",
|
|
107
110
|
longDescription: "root is the whole arrangement and replaces the stored one. A tile is {entity:'@helper'} or {entity:'app:@workspace/main'}; a split is {direction:'horizontal',weights:[1,1],children:[tile,tile]}. horizontal means left/right, vertical means top/bottom, and weights give the ratio of the two children. App left, chat right at 50:50: {root:{direction:'horizontal',weights:[1,1],children:[{entity:'app:@workspace/main'},{entity:'@helper'}]}}. One tile above two tiles at 2:1: {root:{direction:'vertical',weights:[2,1],children:[{entity:'@lead'},{direction:'horizontal',weights:[1,1],children:[{entity:'@first'},{entity:'@second'}]}]}}. root:null clears the surface. Dividers are draggable, so do not resend a layout to fight a personal arrangement. Participants you do not place stay reachable through the run header."
|
|
108
111
|
};
|
|
112
|
+
var placeToolMetadata = {
|
|
113
|
+
name: "canvas_layout_place",
|
|
114
|
+
label: "Place on Surface",
|
|
115
|
+
description: "Place one actor or mini-app next to the current surface layout instead of replacing it.",
|
|
116
|
+
longDescription: "entity is {entity} of a tile: '@helper' or 'app:@workspace/main'. The current arrangement becomes one side of a new split and the entity the other: direction 'horizontal' (default) puts it to the right, 'vertical' below. weight is its share against the existing arrangement's weight 1, default 1. An entity the layout already shows stays where it is; placed is then false. On an empty surface the entity becomes the only tile. Use it when you join a running run, such as a run script started with start.embedded, so that the tiles others arranged stay."
|
|
117
|
+
};
|
|
109
118
|
var canDesignSurface = defineToolAvailability({
|
|
110
119
|
availability: "conditional",
|
|
111
120
|
availabilityDetail: "Only for agents and TypeScript actors with the capability plugin.state.write.",
|
|
@@ -178,6 +187,41 @@ var checkLayoutAgainstRun = (view, input) => {
|
|
|
178
187
|
}
|
|
179
188
|
return layout;
|
|
180
189
|
};
|
|
190
|
+
var currentLayout = (view) => {
|
|
191
|
+
const state = view.pluginStates.find((entry) => entry.pluginId === ORCHESTRATION_PLUGIN_ID && entry.scope.kind === "run")?.state;
|
|
192
|
+
return state === void 0 || state === null ? { root: null } : surfaceLayoutOf(state);
|
|
193
|
+
};
|
|
194
|
+
var placed = (view, request) => {
|
|
195
|
+
const current = currentLayout(view);
|
|
196
|
+
const [tile] = surfaceTileEntities(checkLayoutAgainstRun(view, parsedLayout({ root: { entity: request.entity } })).root);
|
|
197
|
+
if (surfaceTileEntities(current.root).includes(tile)) return void 0;
|
|
198
|
+
const root = current.root === null ? { entity: tile } : {
|
|
199
|
+
direction: request.direction ?? "horizontal",
|
|
200
|
+
weights: [1, request.weight ?? 1],
|
|
201
|
+
children: [current.root, { entity: tile }]
|
|
202
|
+
};
|
|
203
|
+
return parsedLayout({ root });
|
|
204
|
+
};
|
|
205
|
+
var placeOnSurface = (runtime) => ({
|
|
206
|
+
place: (context, runId, request) => {
|
|
207
|
+
const layout = placed(runtime().view(runId), request);
|
|
208
|
+
if (!layout) return { placed: false };
|
|
209
|
+
runtime().replacePluginState(context, runId, { pluginId: ORCHESTRATION_PLUGIN_ID, scope: { kind: "run" }, state: layout });
|
|
210
|
+
return { placed: true };
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
var placeSchema = Type.Object({
|
|
214
|
+
entity: Type.String({ minLength: 1, description: "Actor @handle or activated mini-app app:@handle/view-key or app:program-name/view-key" }),
|
|
215
|
+
direction: Type.Optional(Type.Union([Type.Literal("horizontal"), Type.Literal("vertical")], { description: "horizontal: to the right of the current layout (default); vertical: below it" })),
|
|
216
|
+
weight: Type.Optional(Type.Number({ exclusiveMinimum: 0, description: "Share of the placed tile against the existing arrangement's weight 1; default 1" }))
|
|
217
|
+
}, { additionalProperties: false });
|
|
218
|
+
var createPlaceTool = () => defineRunFunction({
|
|
219
|
+
...placeToolMetadata,
|
|
220
|
+
schema: placeSchema,
|
|
221
|
+
resultSchema: Type.Object({ placed: Type.Boolean() }, { additionalProperties: false }),
|
|
222
|
+
available: canDesignSurface,
|
|
223
|
+
run: ({ runtime, caller, context }, toolCallId, input) => placeOnSurface(() => runtime).place(context(toolCallId), caller.runId, input)
|
|
224
|
+
});
|
|
181
225
|
var createSurfaceTool = () => defineRunFunction({
|
|
182
226
|
...surfaceToolMetadata,
|
|
183
227
|
schema: surfaceLayoutSchema,
|
|
@@ -196,8 +240,8 @@ var createSurfaceTool = () => defineRunFunction({
|
|
|
196
240
|
});
|
|
197
241
|
var createSurfaceToolContributor = () => ({
|
|
198
242
|
name: "ragents.orchestration.surface",
|
|
199
|
-
descriptors: [toolDescriptorFrom(surfaceToolMetadata, canDesignSurface)],
|
|
200
|
-
tools: () => [createSurfaceTool()]
|
|
243
|
+
descriptors: [toolDescriptorFrom(surfaceToolMetadata, canDesignSurface), toolDescriptorFrom(placeToolMetadata, canDesignSurface)],
|
|
244
|
+
tools: () => [createSurfaceTool(), createPlaceTool()]
|
|
201
245
|
});
|
|
202
246
|
|
|
203
247
|
// server/run-stop-tool.ts
|
|
@@ -236,6 +280,7 @@ var orchestrationPlugin = {
|
|
|
236
280
|
manifest: { id: "ragents.orchestration" },
|
|
237
281
|
register: (host) => {
|
|
238
282
|
host.functions(createSurfaceToolContributor());
|
|
283
|
+
host.provide(surfacePlacementToken, placeOnSurface(host.service(runtimeProviderToken)));
|
|
239
284
|
host.functions(createRunStopContributor(
|
|
240
285
|
(runId) => host.service(runManagementToken)().stop(runId),
|
|
241
286
|
(error) => console.error("Run stop by the coordinator failed", error)
|
|
@@ -265,7 +310,8 @@ var orchestrationPlugin = {
|
|
|
265
310
|
handlebarsPrompt("ragents.orchestration.prompt", 600, pluginAsset("ragents.orchestration", "orchestration.hbs")),
|
|
266
311
|
boundToTools(
|
|
267
312
|
handlebarsPrompt("ragents.orchestration.surface", 650, pluginAsset("ragents.orchestration", "surface.hbs")),
|
|
268
|
-
"canvas_layout_replace"
|
|
313
|
+
"canvas_layout_replace",
|
|
314
|
+
"canvas_layout_place"
|
|
269
315
|
)
|
|
270
316
|
);
|
|
271
317
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../plugins/ragents.orchestration/server/index.ts", "../../../plugins/ragents.orchestration/server/surface-tool.ts", "../../../plugins/ragents.orchestration/contract.ts", "../../../plugins/ragents.orchestration/tiled-layout.ts", "../../../plugins/ragents.orchestration/server/run-stop-tool.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n actorInputSchema,\n agentTools,\n enqueueActorInput,\n eventResultSchemaOf,\n ScriptDriver,\n type ActorInputRequest,\n type RAgentsPlugin,\n} from \"@ragents/engine\";\nimport { runtimeProviderToken } from \"@ragents/host/ragents/host-services.js\";\nimport { pluginAsset } from \"@ragents/host/plugin-support/plugin-folder.js\";\nimport type { PluginModule } from \"@ragents/host/plugin-support/plugin-module.js\";\nimport { boundToTools, handlebarsPrompt } from \"@ragents/host/plugin-support/prompt.js\";\nimport { createSurfaceToolContributor } from \"./surface-tool.js\";\nimport { createRunStopContributor } from \"./run-stop-tool.js\";\nimport { runManagementToken } from \"@ragents/host/ragents/global-chat.js\";\n\nconst orchestrationPlugin: RAgentsPlugin = {\n manifest: { id: \"ragents.orchestration\" },\n register: (host) => {\n host.functions(createSurfaceToolContributor());\n host.functions(createRunStopContributor(\n (runId) => host.service(runManagementToken)().stop(runId),\n (error) => console.error(\"Run stop by the coordinator failed\", error),\n ));\n host.operations({\n id: \"actor_input\",\n label: \"Enqueue actor input\",\n description: \"Enqueues a normal text input for an actor under the bound identity - \"\n + \"as an agent or, from an app action, as the owner of the run. Only confirms the enqueueing. TypeScript actors understand only their programmed input protocol, no free-form tasks.\",\n schema: actorInputSchema,\n resultSchema: eventResultSchemaOf(\"actor.input.enqueued\"),\n operator: \"direct\",\n execute: (context, input) =>\n enqueueActorInput(host.service(runtimeProviderToken)(), {\n actorId: context.principal.actorId,\n commandId: context.invocationId,\n ...(context.principal.kind === \"agent\" && context.principal.turnId\n ? { turnId: context.principal.turnId }\n : {}),\n correlationId: context.invocationId,\n causationId: context.invocationId,\n }, context.runId, input as ActorInputRequest),\n });\n host.script({\n id: \"typescript\",\n create: (context) => ({\n driver: new ScriptDriver({ runtime: context.runtime }),\n }),\n });\n host.prompts(\n handlebarsPrompt(\"ragents.orchestration.prompt\", 600, pluginAsset(\"ragents.orchestration\", \"orchestration.hbs\")),\n boundToTools(\n handlebarsPrompt(\"ragents.orchestration.surface\", 650, pluginAsset(\"ragents.orchestration\", \"surface.hbs\")),\n \"canvas_layout_replace\",\n ),\n );\n },\n};\n\nexport const plugin: PluginModule = { create: () => orchestrationPlugin };\n", "import { Type } from \"typebox\";\nimport {\n DomainError,\n actorByHandle,\n defineRunFunction,\n defineToolAvailability,\n holdsUsable,\n type RunFunction,\n type RunView,\n type ToolContributor,\n} from \"@ragents/engine\";\nimport { toolDescriptorFrom } from \"@ragents/host/plugin-support/agent-tool.js\";\nimport { ACTOR_PROGRAMS_STATE_ID, resolveActorView, type ActorProgramState } from \"@ragents/host/plugin-support/actor-programs/contract.js\";\nimport {\n ORCHESTRATION_PLUGIN_ID,\n surfaceEntityOf,\n surfaceLayoutOf,\n type SurfaceLayout,\n} from \"../contract.js\";\nimport { surfaceTileEntities, mapSurfaceTileEntities } from \"../tiled-layout.js\";\n\nexport const surfaceToolMetadata = {\n name: \"canvas_layout_replace\",\n label: \"Replace Surface Layout\",\n description: \"Arrange actors and mini-apps as tiles on the viewport-filling work surface, using a binary tree of weighted splits.\",\n longDescription: \"root is the whole arrangement and replaces the stored one. A tile is {entity:'@helper'} or \"\n + \"{entity:'app:@workspace/main'}; a split is {direction:'horizontal',weights:[1,1],children:[tile,tile]}. \"\n + \"horizontal means left/right, vertical means top/bottom, and weights give the ratio of the two children. \"\n + \"App left, chat right at 50:50: {root:{direction:'horizontal',weights:[1,1],children:[\"\n + \"{entity:'app:@workspace/main'},{entity:'@helper'}]}}. One tile above two tiles at 2:1: \"\n + \"{root:{direction:'vertical',weights:[2,1],children:[{entity:'@lead'},\"\n + \"{direction:'horizontal',weights:[1,1],children:[{entity:'@first'},{entity:'@second'}]}]}}. \"\n + \"root:null clears the surface. Dividers are draggable, so do not resend a layout to fight a personal arrangement. \"\n + \"Participants you do not place stay reachable through the run header.\",\n} as const;\n\nexport const canDesignSurface = defineToolAvailability({\n availability: \"conditional\",\n availabilityDetail: \"Only for agents and TypeScript actors with the capability plugin.state.write.\",\n requiredCapabilities: [\"plugin.state.write\"],\n}, (actor) => actor.kind !== \"human\" && holdsUsable(actor, \"plugin.state.write\"));\n\nconst tileSchema = Type.Cyclic({\n SurfaceTile: Type.Union([\n Type.Object({\n entity: Type.String({ minLength: 1, description: \"Actor @handle or activated mini-app app:@handle/view-key or app:program-name/view-key; the server resolves the view ID\" }),\n chatInput: Type.Optional(Type.Boolean({ description: \"Actor tiles only: false hides the chat composer in the tile; default true. Does not change permissions or the inspector\" })),\n }, { additionalProperties: false }),\n Type.Object({\n direction: Type.Union([Type.Literal(\"horizontal\"), Type.Literal(\"vertical\")]),\n weights: Type.Tuple([Type.Number({ exclusiveMinimum: 0 }), Type.Number({ exclusiveMinimum: 0 })]),\n children: Type.Tuple([Type.Ref(\"SurfaceTile\"), Type.Ref(\"SurfaceTile\")]),\n }, { additionalProperties: false }),\n ]),\n}, \"SurfaceTile\");\n\nconst surfaceLayoutSchema = Type.Object({\n root: Type.Union([tileSchema, Type.Null()], { description: \"The whole arrangement: a tile or a binary split. Maximum 64 unique tiles and 16 nested splits. null clears the surface\" }),\n});\n\nconst invalid = (message: string) => new DomainError(\"invalid-surface-layout\", message, 400);\n\nconst parsedLayout = (input: unknown): SurfaceLayout => {\n try {\n return surfaceLayoutOf(input);\n } catch (caught) {\n throw invalid(caught instanceof Error ? caught.message : String(caught));\n }\n};\n\nconst isStopped = (actor: RunView[\"actors\"][number]) => actor.kind !== \"human\" && actor.lifecycle.kind === \"stopped\";\n\nconst surfaceActorOf = (view: RunView, reference: string, where: string) => {\n const entity = surfaceEntityOf(reference);\n if (entity.kind !== \"actor\") throw invalid(`${where}: ${reference} is not an actor`);\n const handle = entity.handle;\n const found = actorByHandle(view.actors, handle);\n if (!found) {\n const known = view.actors.filter((actor) => actor.kind !== \"human\").map((actor) => `@${actor.handle}`);\n throw invalid(`${where}: @${handle} is not an actor of this run. Present: ${known.join(\", \") || \"none\"}`);\n }\n if (found.kind === \"human\") {\n throw invalid(`${where}: @${handle} is the human in the chat; the chat is fixed to the left of the surface`);\n }\n return found;\n};\n\nconst isActorReference = (reference: string) => surfaceEntityOf(reference).kind === \"actor\";\n\nconst resolveAppReferences = (view: RunView, layout: SurfaceLayout): SurfaceLayout => {\n const programs = view.pluginStates.flatMap((entry) => {\n if (entry.pluginId !== ACTOR_PROGRAMS_STATE_ID || entry.scope.kind !== \"actor\") return [];\n const actorId = entry.scope.actorId;\n const actor = view.actors.find((candidate) => candidate.id === actorId);\n if (!actor || actor.kind === \"human\" || isStopped(actor)) return [];\n const { program } = entry.state as unknown as ActorProgramState;\n return program ? [program] : [];\n });\n const resolve = (reference: string, where: string): string => {\n const entity = surfaceEntityOf(reference);\n if (entity.kind !== \"app\") return reference;\n try {\n return `app:${resolveActorView(programs, entity.id).view.id}`;\n } catch (error) {\n throw invalid(`${where}: ${reference}: ${error instanceof Error ? error.message : String(error)} Surface entities get the prefix app:.`);\n }\n };\n return parsedLayout({ root: layout.root ? mapSurfaceTileEntities(layout.root, (entity) => resolve(entity, \"root\")) : null });\n};\n\n/** Resolve app names and validate the placed actors before any layout is stored. */\nexport const checkLayoutAgainstRun = (view: RunView, input: SurfaceLayout): SurfaceLayout => {\n const layout = resolveAppReferences(view, input);\n for (const reference of surfaceTileEntities(layout.root)) {\n if (isActorReference(reference)) surfaceActorOf(view, reference, \"root\");\n }\n return layout;\n};\n\nexport const createSurfaceTool = (): RunFunction =>\n defineRunFunction({\n ...surfaceToolMetadata,\n schema: surfaceLayoutSchema,\n resultSchema: Type.Null(),\n available: canDesignSurface,\n run: ({ runtime, caller, context }, toolCallId, input) => {\n const view = runtime.view(caller.runId);\n const layout = checkLayoutAgainstRun(view, parsedLayout(input));\n runtime.replacePluginState(context(toolCallId), caller.runId, {\n pluginId: ORCHESTRATION_PLUGIN_ID,\n scope: { kind: \"run\" },\n state: layout,\n });\n return null;\n },\n });\n\nexport const createSurfaceToolContributor = (): ToolContributor => ({\n name: \"ragents.orchestration.surface\",\n descriptors: [toolDescriptorFrom(surfaceToolMetadata, canDesignSurface)],\n tools: () => [createSurfaceTool()],\n});\n", "import { handleKey } from \"@ragents/engine/src/http/contracts\";\nimport { surfaceTileNodeOf } from \"./tiled-layout.js\";\n\nexport const ORCHESTRATION_PLUGIN_ID = \"ragents.orchestration\";\n\nexport type SurfaceEntity =\n | { kind: \"actor\"; handle: string }\n | { kind: \"app\"; id: string };\n\nexport type SurfaceTileNode =\n | { entity: string; chatInput?: boolean }\n | { direction: \"horizontal\" | \"vertical\"; weights: [number, number]; children: [SurfaceTileNode, SurfaceTileNode] };\n\nexport type SurfaceLayout = {\n root: SurfaceTileNode | null;\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nexport const surfaceEntityOf = (text: string): SurfaceEntity => {\n const trimmed = text.trim();\n if (trimmed.startsWith(\"@\")) {\n const handle = handleKey(trimmed);\n if (!handle || /\\s/.test(handle)) throw new Error(`Entity ${JSON.stringify(text)}: a handle is missing after the @`);\n return { kind: \"actor\", handle };\n }\n const match = /^app:(.+)$/s.exec(trimmed);\n if (!match) {\n throw new Error(`Entity ${JSON.stringify(text)}: expected @handle or app:<id>`);\n }\n const id = match[1].trim();\n if (!id) throw new Error(`Entity ${JSON.stringify(text)}: the ID after the colon is empty`);\n return { kind: \"app\", id };\n};\n\nexport const surfaceEntityKey = (entity: SurfaceEntity): string =>\n entity.kind === \"actor\" ? `@${entity.handle}` : `app:${entity.id}`;\n\nconst LEGACY_KEYS = [\"nodes\", \"shapes\", \"lines\", \"mode\"] as const;\n\n/** Parses and validates a tile layout; throws an error naming the first violation. */\nexport const surfaceLayoutOf = (value: unknown): SurfaceLayout => {\n if (!isRecord(value)) throw new Error(\"The arrangement must be an object with root\");\n const legacy = LEGACY_KEYS.filter((key) => key in value);\n if (legacy.length > 0) {\n throw new Error(`The program arrangement comes from the removed free surface (${legacy.join(\", \")}); `\n + \"canvas_layout_replace with root sets it anew as a tile layout\");\n }\n if (!(\"root\" in value)) throw new Error(\"root is missing; expected a tile, a split or null\");\n return { root: value.root === null ? null : surfaceTileNodeOf(value.root) };\n};\n", "import { surfaceEntityKey, surfaceEntityOf, type SurfaceTileNode } from \"./contract.js\";\n\nexport type { SurfaceTileNode } from \"./contract.js\";\n\nexport const MAX_SURFACE_TILE_DEPTH = 16;\nexport const MAX_SURFACE_TILES = 64;\n\nexport const surfaceTileNodeOf = (input: unknown): SurfaceTileNode => {\n const entities = new Set<string>();\n const parse = (value: unknown, where: string, depth: number): SurfaceTileNode => {\n if (depth > MAX_SURFACE_TILE_DEPTH) throw new Error(`${where}: at most ${MAX_SURFACE_TILE_DEPTH} nested splits are allowed`);\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) throw new Error(`${where} must be a tile or a split`);\n const node = value as Record<string, unknown>;\n if (Object.hasOwn(node, \"entity\")) {\n if (Object.keys(node).some((key) => key !== \"entity\" && key !== \"chatInput\")) throw new Error(`${where}: a tile carries only entity and chatInput; a split direction, weights and children`);\n if (typeof node.entity !== \"string\") throw new Error(`${where}.entity must be @handle or app:<name>/<view>`);\n const entity = surfaceEntityOf(node.entity);\n const key = surfaceEntityKey(entity);\n if (node.chatInput !== undefined && (entity.kind !== \"actor\" || typeof node.chatInput !== \"boolean\")) {\n throw new Error(`${where}.chatInput is only allowed for actors, as a boolean`);\n }\n if (entities.has(key)) throw new Error(`${where}: ${key} is placed as a tile more than once`);\n entities.add(key);\n if (entities.size > MAX_SURFACE_TILES) throw new Error(`At most ${MAX_SURFACE_TILES} tiles are allowed`);\n return node.chatInput === undefined ? { entity: key } : { entity: key, chatInput: node.chatInput as boolean };\n }\n if (Object.keys(node).some((key) => ![\"direction\", \"weights\", \"children\"].includes(key))) throw new Error(`${where}: a split carries only direction, weights and children`);\n if (node.direction !== \"horizontal\" && node.direction !== \"vertical\") throw new Error(`${where}.direction must be horizontal or vertical`);\n if (!Array.isArray(node.weights) || node.weights.length !== 2 || node.weights.some((weight) => typeof weight !== \"number\" || !Number.isFinite(weight) || weight <= 0)) {\n throw new Error(`${where}.weights must contain exactly two finite positive numbers`);\n }\n if (!Array.isArray(node.children) || node.children.length !== 2) throw new Error(`${where}.children must contain exactly two tiles or splits`);\n return {\n direction: node.direction,\n weights: [node.weights[0], node.weights[1]],\n children: [parse(node.children[0], `${where}.children[0]`, depth + 1), parse(node.children[1], `${where}.children[1]`, depth + 1)],\n };\n };\n return parse(input, \"root\", 0);\n};\n\n/** A tile hides the chat composer of its actor only when its leaf says chatInput: false. */\nexport const surfaceTileChatInput = (root: SurfaceTileNode | null | undefined, entity: string): boolean =>\n !root ? true : \"entity\" in root\n ? root.entity !== entity || root.chatInput !== false\n : surfaceTileChatInput(root.children[0], entity) && surfaceTileChatInput(root.children[1], entity);\n\nexport const surfaceTileEntities = (root: SurfaceTileNode | null | undefined): string[] =>\n !root ? [] : \"entity\" in root ? [root.entity] : root.children.flatMap(surfaceTileEntities);\n\nexport const mapSurfaceTileEntities = (root: SurfaceTileNode, resolve: (entity: string) => string): SurfaceTileNode =>\n \"entity\" in root ? { ...root, entity: resolve(root.entity) } : {\n ...root,\n children: [mapSurfaceTileEntities(root.children[0], resolve), mapSurfaceTileEntities(root.children[1], resolve)],\n };\n", "import { Type } from \"typebox\";\nimport { defineRunFunction, defineToolAvailability, holdsUsable, type ToolContributor } from \"@ragents/engine\";\nimport { toolDescriptorFrom } from \"@ragents/host/plugin-support/agent-tool.js\";\n\nconst available = defineToolAvailability({\n availability: \"conditional\",\n availabilityDetail: \"For the primary actor with execution.stopOwned in its own run.\",\n requiredCapabilities: [\"execution.stopOwned\"],\n}, (actor, view) => actor.kind !== \"human\" && actor.id === view.primaryActorId && holdsUsable(actor, \"execution.stopOwned\"));\n\nexport const createRunStopContributor = (stop: (runId: string) => Promise<void>, onError: (error: unknown) => void): ToolContributor => {\n const definition = defineRunFunction({\n name: \"run_stop\",\n label: \"Stop run\",\n description: \"Initiates the complete stop of your own run: running turns, tools, subagents and plugin services. Conversation and files are kept. Also cancels your own turn; acceptance is not a confirmation of completed cleanup. Use immediately when the user wants a complete cancellation; do not send a cancel message to busy agents.\",\n schema: Type.Object({}, { additionalProperties: false }),\n resultSchema: Type.Object({ requested: Type.Literal(true) }, { additionalProperties: false }),\n available,\n run: ({ caller, signal }) => {\n signal?.throwIfAborted();\n void stop(caller.runId).catch(onError);\n return { requested: true as const };\n },\n });\n return {\n name: \"ragents.orchestration.run-stop\",\n descriptors: [toolDescriptorFrom(definition, available)],\n tools: () => [definition],\n };\n};\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import {\n actorInputSchema,\n agentTools,\n enqueueActorInput,\n eventResultSchemaOf,\n ScriptDriver,\n type ActorInputRequest,\n type RAgentsPlugin,\n} from \"@ragents/engine\";\nimport { runtimeProviderToken } from \"@ragents/host/ragents/host-services.js\";\nimport { pluginAsset } from \"@ragents/host/plugin-support/plugin-folder.js\";\nimport type { PluginModule } from \"@ragents/host/plugin-support/plugin-module.js\";\nimport { boundToTools, handlebarsPrompt } from \"@ragents/host/plugin-support/prompt.js\";\nimport { createSurfaceToolContributor, placeOnSurface } from \"./surface-tool.js\";\nimport { surfacePlacementToken } from \"./contract.js\";\nimport { createRunStopContributor } from \"./run-stop-tool.js\";\nimport { runManagementToken } from \"@ragents/host/ragents/global-chat.js\";\n\nconst orchestrationPlugin: RAgentsPlugin = {\n manifest: { id: \"ragents.orchestration\" },\n register: (host) => {\n host.functions(createSurfaceToolContributor());\n host.provide(surfacePlacementToken, placeOnSurface(host.service(runtimeProviderToken)));\n host.functions(createRunStopContributor(\n (runId) => host.service(runManagementToken)().stop(runId),\n (error) => console.error(\"Run stop by the coordinator failed\", error),\n ));\n host.operations({\n id: \"actor_input\",\n label: \"Enqueue actor input\",\n description: \"Enqueues a normal text input for an actor under the bound identity - \"\n + \"as an agent or, from an app action, as the owner of the run. Only confirms the enqueueing. TypeScript actors understand only their programmed input protocol, no free-form tasks.\",\n schema: actorInputSchema,\n resultSchema: eventResultSchemaOf(\"actor.input.enqueued\"),\n operator: \"direct\",\n execute: (context, input) =>\n enqueueActorInput(host.service(runtimeProviderToken)(), {\n actorId: context.principal.actorId,\n commandId: context.invocationId,\n ...(context.principal.kind === \"agent\" && context.principal.turnId\n ? { turnId: context.principal.turnId }\n : {}),\n correlationId: context.invocationId,\n causationId: context.invocationId,\n }, context.runId, input as ActorInputRequest),\n });\n host.script({\n id: \"typescript\",\n create: (context) => ({\n driver: new ScriptDriver({ runtime: context.runtime }),\n }),\n });\n host.prompts(\n handlebarsPrompt(\"ragents.orchestration.prompt\", 600, pluginAsset(\"ragents.orchestration\", \"orchestration.hbs\")),\n boundToTools(\n handlebarsPrompt(\"ragents.orchestration.surface\", 650, pluginAsset(\"ragents.orchestration\", \"surface.hbs\")),\n \"canvas_layout_replace\",\n \"canvas_layout_place\",\n ),\n );\n },\n};\n\nexport const plugin: PluginModule = { create: () => orchestrationPlugin };\n", "import { Type } from \"typebox\";\nimport {\n DomainError,\n actorByHandle,\n defineRunFunction,\n defineToolAvailability,\n holdsUsable,\n type CommandContext,\n type Orchestration,\n type RunFunction,\n type RunView,\n type ToolContributor,\n} from \"@ragents/engine\";\nimport { toolDescriptorFrom } from \"@ragents/host/plugin-support/agent-tool.js\";\nimport { ACTOR_PROGRAMS_STATE_ID, resolveActorView, type ActorProgramState } from \"@ragents/host/plugin-support/actor-programs/contract.js\";\nimport {\n ORCHESTRATION_PLUGIN_ID,\n surfaceEntityOf,\n surfaceLayoutOf,\n type SurfaceLayout,\n} from \"../contract.js\";\nimport { surfaceTileEntities, mapSurfaceTileEntities } from \"../tiled-layout.js\";\nimport type { SurfacePlacement, SurfacePlacementRequest } from \"./contract.js\";\n\nexport const surfaceToolMetadata = {\n name: \"canvas_layout_replace\",\n label: \"Replace Surface Layout\",\n description: \"Arrange actors and mini-apps as tiles on the viewport-filling work surface, using a binary tree of weighted splits.\",\n longDescription: \"root is the whole arrangement and replaces the stored one. A tile is {entity:'@helper'} or \"\n + \"{entity:'app:@workspace/main'}; a split is {direction:'horizontal',weights:[1,1],children:[tile,tile]}. \"\n + \"horizontal means left/right, vertical means top/bottom, and weights give the ratio of the two children. \"\n + \"App left, chat right at 50:50: {root:{direction:'horizontal',weights:[1,1],children:[\"\n + \"{entity:'app:@workspace/main'},{entity:'@helper'}]}}. One tile above two tiles at 2:1: \"\n + \"{root:{direction:'vertical',weights:[2,1],children:[{entity:'@lead'},\"\n + \"{direction:'horizontal',weights:[1,1],children:[{entity:'@first'},{entity:'@second'}]}]}}. \"\n + \"root:null clears the surface. Dividers are draggable, so do not resend a layout to fight a personal arrangement. \"\n + \"Participants you do not place stay reachable through the run header.\",\n} as const;\n\nexport const placeToolMetadata = {\n name: \"canvas_layout_place\",\n label: \"Place on Surface\",\n description: \"Place one actor or mini-app next to the current surface layout instead of replacing it.\",\n longDescription: \"entity is {entity} of a tile: '@helper' or 'app:@workspace/main'. The current arrangement becomes one side of a new split \"\n + \"and the entity the other: direction 'horizontal' (default) puts it to the right, 'vertical' below. weight is its share against \"\n + \"the existing arrangement's weight 1, default 1. An entity the layout already shows stays where it is; placed is then false. \"\n + \"On an empty surface the entity becomes the only tile. Use it when you join a running run, such as a run script started with \"\n + \"start.embedded, so that the tiles others arranged stay.\",\n} as const;\n\nexport const canDesignSurface = defineToolAvailability({\n availability: \"conditional\",\n availabilityDetail: \"Only for agents and TypeScript actors with the capability plugin.state.write.\",\n requiredCapabilities: [\"plugin.state.write\"],\n}, (actor) => actor.kind !== \"human\" && holdsUsable(actor, \"plugin.state.write\"));\n\nconst tileSchema = Type.Cyclic({\n SurfaceTile: Type.Union([\n Type.Object({\n entity: Type.String({ minLength: 1, description: \"Actor @handle or activated mini-app app:@handle/view-key or app:program-name/view-key; the server resolves the view ID\" }),\n chatInput: Type.Optional(Type.Boolean({ description: \"Actor tiles only: false hides the chat composer in the tile; default true. Does not change permissions or the inspector\" })),\n }, { additionalProperties: false }),\n Type.Object({\n direction: Type.Union([Type.Literal(\"horizontal\"), Type.Literal(\"vertical\")]),\n weights: Type.Tuple([Type.Number({ exclusiveMinimum: 0 }), Type.Number({ exclusiveMinimum: 0 })]),\n children: Type.Tuple([Type.Ref(\"SurfaceTile\"), Type.Ref(\"SurfaceTile\")]),\n }, { additionalProperties: false }),\n ]),\n}, \"SurfaceTile\");\n\nconst surfaceLayoutSchema = Type.Object({\n root: Type.Union([tileSchema, Type.Null()], { description: \"The whole arrangement: a tile or a binary split. Maximum 64 unique tiles and 16 nested splits. null clears the surface\" }),\n});\n\nconst invalid = (message: string) => new DomainError(\"invalid-surface-layout\", message, 400);\n\nconst parsedLayout = (input: unknown): SurfaceLayout => {\n try {\n return surfaceLayoutOf(input);\n } catch (caught) {\n throw invalid(caught instanceof Error ? caught.message : String(caught));\n }\n};\n\nconst isStopped = (actor: RunView[\"actors\"][number]) => actor.kind !== \"human\" && actor.lifecycle.kind === \"stopped\";\n\nconst surfaceActorOf = (view: RunView, reference: string, where: string) => {\n const entity = surfaceEntityOf(reference);\n if (entity.kind !== \"actor\") throw invalid(`${where}: ${reference} is not an actor`);\n const handle = entity.handle;\n const found = actorByHandle(view.actors, handle);\n if (!found) {\n const known = view.actors.filter((actor) => actor.kind !== \"human\").map((actor) => `@${actor.handle}`);\n throw invalid(`${where}: @${handle} is not an actor of this run. Present: ${known.join(\", \") || \"none\"}`);\n }\n if (found.kind === \"human\") {\n throw invalid(`${where}: @${handle} is the human in the chat; the chat is fixed to the left of the surface`);\n }\n return found;\n};\n\nconst isActorReference = (reference: string) => surfaceEntityOf(reference).kind === \"actor\";\n\nconst resolveAppReferences = (view: RunView, layout: SurfaceLayout): SurfaceLayout => {\n const programs = view.pluginStates.flatMap((entry) => {\n if (entry.pluginId !== ACTOR_PROGRAMS_STATE_ID || entry.scope.kind !== \"actor\") return [];\n const actorId = entry.scope.actorId;\n const actor = view.actors.find((candidate) => candidate.id === actorId);\n if (!actor || actor.kind === \"human\" || isStopped(actor)) return [];\n const { program } = entry.state as unknown as ActorProgramState;\n return program ? [program] : [];\n });\n const resolve = (reference: string, where: string): string => {\n const entity = surfaceEntityOf(reference);\n if (entity.kind !== \"app\") return reference;\n try {\n return `app:${resolveActorView(programs, entity.id).view.id}`;\n } catch (error) {\n throw invalid(`${where}: ${reference}: ${error instanceof Error ? error.message : String(error)} Surface entities get the prefix app:.`);\n }\n };\n return parsedLayout({ root: layout.root ? mapSurfaceTileEntities(layout.root, (entity) => resolve(entity, \"root\")) : null });\n};\n\n/** Resolve app names and validate the placed actors before any layout is stored. */\nexport const checkLayoutAgainstRun = (view: RunView, input: SurfaceLayout): SurfaceLayout => {\n const layout = resolveAppReferences(view, input);\n for (const reference of surfaceTileEntities(layout.root)) {\n if (isActorReference(reference)) surfaceActorOf(view, reference, \"root\");\n }\n return layout;\n};\n\nconst currentLayout = (view: RunView): SurfaceLayout => {\n const state = view.pluginStates.find((entry) => entry.pluginId === ORCHESTRATION_PLUGIN_ID && entry.scope.kind === \"run\")?.state;\n return state === undefined || state === null ? { root: null } : surfaceLayoutOf(state);\n};\n\n/** Splits the root once: the existing arrangement keeps weight 1, the placed tile gets its own. */\nconst placed = (view: RunView, request: SurfacePlacementRequest): SurfaceLayout | undefined => {\n const current = currentLayout(view);\n const [tile] = surfaceTileEntities(checkLayoutAgainstRun(view, parsedLayout({ root: { entity: request.entity } })).root);\n if (surfaceTileEntities(current.root).includes(tile!)) return undefined;\n const root = current.root === null ? { entity: tile! } : {\n direction: request.direction ?? \"horizontal\",\n weights: [1, request.weight ?? 1],\n children: [current.root, { entity: tile! }],\n };\n return parsedLayout({ root });\n};\n\nexport const placeOnSurface = (runtime: () => Orchestration): SurfacePlacement => ({\n place: (context: CommandContext, runId: string, request: SurfacePlacementRequest) => {\n const layout = placed(runtime().view(runId), request);\n if (!layout) return { placed: false };\n runtime().replacePluginState(context, runId, { pluginId: ORCHESTRATION_PLUGIN_ID, scope: { kind: \"run\" }, state: layout });\n return { placed: true };\n },\n});\n\nconst placeSchema = Type.Object({\n entity: Type.String({ minLength: 1, description: \"Actor @handle or activated mini-app app:@handle/view-key or app:program-name/view-key\" }),\n direction: Type.Optional(Type.Union([Type.Literal(\"horizontal\"), Type.Literal(\"vertical\")], { description: \"horizontal: to the right of the current layout (default); vertical: below it\" })),\n weight: Type.Optional(Type.Number({ exclusiveMinimum: 0, description: \"Share of the placed tile against the existing arrangement's weight 1; default 1\" })),\n}, { additionalProperties: false });\n\nexport const createPlaceTool = (): RunFunction =>\n defineRunFunction({\n ...placeToolMetadata,\n schema: placeSchema,\n resultSchema: Type.Object({ placed: Type.Boolean() }, { additionalProperties: false }),\n available: canDesignSurface,\n run: ({ runtime, caller, context }, toolCallId, input) => placeOnSurface(() => runtime).place(context(toolCallId), caller.runId, input),\n });\n\nexport const createSurfaceTool = (): RunFunction =>\n defineRunFunction({\n ...surfaceToolMetadata,\n schema: surfaceLayoutSchema,\n resultSchema: Type.Null(),\n available: canDesignSurface,\n run: ({ runtime, caller, context }, toolCallId, input) => {\n const view = runtime.view(caller.runId);\n const layout = checkLayoutAgainstRun(view, parsedLayout(input));\n runtime.replacePluginState(context(toolCallId), caller.runId, {\n pluginId: ORCHESTRATION_PLUGIN_ID,\n scope: { kind: \"run\" },\n state: layout,\n });\n return null;\n },\n });\n\nexport const createSurfaceToolContributor = (): ToolContributor => ({\n name: \"ragents.orchestration.surface\",\n descriptors: [toolDescriptorFrom(surfaceToolMetadata, canDesignSurface), toolDescriptorFrom(placeToolMetadata, canDesignSurface)],\n tools: () => [createSurfaceTool(), createPlaceTool()],\n});\n", "import { handleKey } from \"@ragents/engine/src/http/contracts\";\nimport { surfaceTileNodeOf } from \"./tiled-layout.js\";\n\nexport const ORCHESTRATION_PLUGIN_ID = \"ragents.orchestration\";\n\nexport type SurfaceEntity =\n | { kind: \"actor\"; handle: string }\n | { kind: \"app\"; id: string };\n\nexport type SurfaceTileNode =\n | { entity: string; chatInput?: boolean }\n | { direction: \"horizontal\" | \"vertical\"; weights: [number, number]; children: [SurfaceTileNode, SurfaceTileNode] };\n\nexport type SurfaceLayout = {\n root: SurfaceTileNode | null;\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nexport const surfaceEntityOf = (text: string): SurfaceEntity => {\n const trimmed = text.trim();\n if (trimmed.startsWith(\"@\")) {\n const handle = handleKey(trimmed);\n if (!handle || /\\s/.test(handle)) throw new Error(`Entity ${JSON.stringify(text)}: a handle is missing after the @`);\n return { kind: \"actor\", handle };\n }\n const match = /^app:(.+)$/s.exec(trimmed);\n if (!match) {\n throw new Error(`Entity ${JSON.stringify(text)}: expected @handle or app:<id>`);\n }\n const id = match[1].trim();\n if (!id) throw new Error(`Entity ${JSON.stringify(text)}: the ID after the colon is empty`);\n return { kind: \"app\", id };\n};\n\nexport const surfaceEntityKey = (entity: SurfaceEntity): string =>\n entity.kind === \"actor\" ? `@${entity.handle}` : `app:${entity.id}`;\n\nconst LEGACY_KEYS = [\"nodes\", \"shapes\", \"lines\", \"mode\"] as const;\n\n/** Parses and validates a tile layout; throws an error naming the first violation. */\nexport const surfaceLayoutOf = (value: unknown): SurfaceLayout => {\n if (!isRecord(value)) throw new Error(\"The arrangement must be an object with root\");\n const legacy = LEGACY_KEYS.filter((key) => key in value);\n if (legacy.length > 0) {\n throw new Error(`The program arrangement comes from the removed free surface (${legacy.join(\", \")}); `\n + \"canvas_layout_replace with root sets it anew as a tile layout\");\n }\n if (!(\"root\" in value)) throw new Error(\"root is missing; expected a tile, a split or null\");\n return { root: value.root === null ? null : surfaceTileNodeOf(value.root) };\n};\n", "import { surfaceEntityKey, surfaceEntityOf, type SurfaceTileNode } from \"./contract.js\";\n\nexport type { SurfaceTileNode } from \"./contract.js\";\n\nexport const MAX_SURFACE_TILE_DEPTH = 16;\nexport const MAX_SURFACE_TILES = 64;\n\nexport const surfaceTileNodeOf = (input: unknown): SurfaceTileNode => {\n const entities = new Set<string>();\n const parse = (value: unknown, where: string, depth: number): SurfaceTileNode => {\n if (depth > MAX_SURFACE_TILE_DEPTH) throw new Error(`${where}: at most ${MAX_SURFACE_TILE_DEPTH} nested splits are allowed`);\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) throw new Error(`${where} must be a tile or a split`);\n const node = value as Record<string, unknown>;\n if (Object.hasOwn(node, \"entity\")) {\n if (Object.keys(node).some((key) => key !== \"entity\" && key !== \"chatInput\")) throw new Error(`${where}: a tile carries only entity and chatInput; a split direction, weights and children`);\n if (typeof node.entity !== \"string\") throw new Error(`${where}.entity must be @handle or app:<name>/<view>`);\n const entity = surfaceEntityOf(node.entity);\n const key = surfaceEntityKey(entity);\n if (node.chatInput !== undefined && (entity.kind !== \"actor\" || typeof node.chatInput !== \"boolean\")) {\n throw new Error(`${where}.chatInput is only allowed for actors, as a boolean`);\n }\n if (entities.has(key)) throw new Error(`${where}: ${key} is placed as a tile more than once`);\n entities.add(key);\n if (entities.size > MAX_SURFACE_TILES) throw new Error(`At most ${MAX_SURFACE_TILES} tiles are allowed`);\n return node.chatInput === undefined ? { entity: key } : { entity: key, chatInput: node.chatInput as boolean };\n }\n if (Object.keys(node).some((key) => ![\"direction\", \"weights\", \"children\"].includes(key))) throw new Error(`${where}: a split carries only direction, weights and children`);\n if (node.direction !== \"horizontal\" && node.direction !== \"vertical\") throw new Error(`${where}.direction must be horizontal or vertical`);\n if (!Array.isArray(node.weights) || node.weights.length !== 2 || node.weights.some((weight) => typeof weight !== \"number\" || !Number.isFinite(weight) || weight <= 0)) {\n throw new Error(`${where}.weights must contain exactly two finite positive numbers`);\n }\n if (!Array.isArray(node.children) || node.children.length !== 2) throw new Error(`${where}.children must contain exactly two tiles or splits`);\n return {\n direction: node.direction,\n weights: [node.weights[0], node.weights[1]],\n children: [parse(node.children[0], `${where}.children[0]`, depth + 1), parse(node.children[1], `${where}.children[1]`, depth + 1)],\n };\n };\n return parse(input, \"root\", 0);\n};\n\n/** A tile hides the chat composer of its actor only when its leaf says chatInput: false. */\nexport const surfaceTileChatInput = (root: SurfaceTileNode | null | undefined, entity: string): boolean =>\n !root ? true : \"entity\" in root\n ? root.entity !== entity || root.chatInput !== false\n : surfaceTileChatInput(root.children[0], entity) && surfaceTileChatInput(root.children[1], entity);\n\nexport const surfaceTileEntities = (root: SurfaceTileNode | null | undefined): string[] =>\n !root ? [] : \"entity\" in root ? [root.entity] : root.children.flatMap(surfaceTileEntities);\n\nexport const mapSurfaceTileEntities = (root: SurfaceTileNode, resolve: (entity: string) => string): SurfaceTileNode =>\n \"entity\" in root ? { ...root, entity: resolve(root.entity) } : {\n ...root,\n children: [mapSurfaceTileEntities(root.children[0], resolve), mapSurfaceTileEntities(root.children[1], resolve)],\n };\n", "import { Type } from \"typebox\";\nimport { defineRunFunction, defineToolAvailability, holdsUsable, type ToolContributor } from \"@ragents/engine\";\nimport { toolDescriptorFrom } from \"@ragents/host/plugin-support/agent-tool.js\";\n\nconst available = defineToolAvailability({\n availability: \"conditional\",\n availabilityDetail: \"For the primary actor with execution.stopOwned in its own run.\",\n requiredCapabilities: [\"execution.stopOwned\"],\n}, (actor, view) => actor.kind !== \"human\" && actor.id === view.primaryActorId && holdsUsable(actor, \"execution.stopOwned\"));\n\nexport const createRunStopContributor = (stop: (runId: string) => Promise<void>, onError: (error: unknown) => void): ToolContributor => {\n const definition = defineRunFunction({\n name: \"run_stop\",\n label: \"Stop run\",\n description: \"Initiates the complete stop of your own run: running turns, tools, subagents and plugin services. Conversation and files are kept. Also cancels your own turn; acceptance is not a confirmation of completed cleanup. Use immediately when the user wants a complete cancellation; do not send a cancel message to busy agents.\",\n schema: Type.Object({}, { additionalProperties: false }),\n resultSchema: Type.Object({ requested: Type.Literal(true) }, { additionalProperties: false }),\n available,\n run: ({ caller, signal }) => {\n signal?.throwIfAborted();\n void stop(caller.runId).catch(onError);\n return { requested: true as const };\n },\n });\n return {\n name: \"ragents.orchestration.run-stop\",\n descriptors: [toolDescriptorFrom(definition, available)],\n tools: () => [definition],\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAE5B,SAAS,cAAc,wBAAwB;;;ACZ/C,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AACP,SAAS,0BAA0B;AACnC,SAAS,yBAA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Aa,QAAQ;AAAA,MACvB,GAAG,QAAQ,OAAO,KAA0B;AAAA,IAChD,CAAC;AACD,SAAK,OAAO;AAAA,MACV,IAAI;AAAA,MACJ,QAAQ,CAAC,aAAa;AAAA,QACpB,QAAQ,IAAI,aAAa,EAAE,SAAS,QAAQ,QAAQ,CAAC;AAAA,MACvD;AAAA,IACF,CAAC;AACD,SAAK;AAAA,MACH,iBAAiB,gCAAgC,KAAK,YAAY,yBAAyB,mBAAmB,CAAC;AAAA,MAC/G;AAAA,QACE,iBAAiB,iCAAiC,KAAK,YAAY,yBAAyB,aAAa,CAAC;AAAA,QAC1G;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,SAAuB,EAAE,QAAQ,MAAM,oBAAoB;",
|
|
6
6
|
"names": ["key", "Type", "defineRunFunction", "defineToolAvailability", "holdsUsable", "toolDescriptorFrom"]
|
|
7
7
|
}
|
|
@@ -19,6 +19,11 @@ App left, chat right at 50:50:
|
|
|
19
19
|
]}}. Resolve the actual actor and app names before calling; the example names are not existing
|
|
20
20
|
participants.
|
|
21
21
|
|
|
22
|
+
To add one tile without replacing what is arranged, `context.functions.canvas_layout_place({ entity })`
|
|
23
|
+
splits the current layout once and puts the entity to its right, or below with `direction: "vertical"`;
|
|
24
|
+
`weight` is its share against the existing arrangement's weight 1. An entity the layout shows already
|
|
25
|
+
stays where it is. A run script started inside a running run (`start.embedded`) uses place, not replace.
|
|
26
|
+
|
|
22
27
|
An actor tile carries {entity:"@helper",chatInput:false} when its chat composer should stay hidden.
|
|
23
28
|
That changes neither permissions nor the inspector. Mini-app tiles have no chatInput.
|
|
24
29
|
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
}
|
|
131
131
|
},
|
|
132
132
|
"revision": "58b8b02a346c4323afdef69cfd96b8f3717806919f2c46f146bcc803ef12bac4",
|
|
133
|
-
"sourceRevision": "
|
|
133
|
+
"sourceRevision": "9310057d7fc569e6a0d103d727131e6644899a9ccf17c9ba79680cc3539c9a16",
|
|
134
134
|
"server": "server/index.js",
|
|
135
135
|
"web": {
|
|
136
136
|
"entry": "web/index.js",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
80
|
"revision": "e602a8711818533fc7372c5cb2ca51ae55362079d9944da008db9084621b5ccc",
|
|
81
|
-
"sourceRevision": "
|
|
81
|
+
"sourceRevision": "0d7379e3a1c3fe42300ff72891203b4c4c043ce8720e58152358571b7af8adf1",
|
|
82
82
|
"server": "server/index.js",
|
|
83
83
|
"web": {
|
|
84
84
|
"entry": "web/index.js",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
"revision": "7a3eb7a847ce6a4c8324b9c073c3c7a13c760088a194d419fe21342575c4208f",
|
|
79
|
-
"sourceRevision": "
|
|
79
|
+
"sourceRevision": "7c8b3522ee90f89a7d3941ea396c458980ac53c83fa5096eab5a19b5f1a7aa81",
|
|
80
80
|
"server": "server/index.js",
|
|
81
81
|
"web": {
|
|
82
82
|
"entry": "web/index.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"web": {}
|
|
54
54
|
},
|
|
55
55
|
"revision": "3e99cf5cb8921685ad83aa6aaf9657da4c648f9d68cb744988a73f227c342e1d",
|
|
56
|
-
"sourceRevision": "
|
|
56
|
+
"sourceRevision": "cbf9d98fe42583b619b84425e648666df7cafd04930cf0692b43a5943fb4bd39",
|
|
57
57
|
"server": "server/index.js",
|
|
58
58
|
"exports": {
|
|
59
59
|
"server": {},
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "notebook",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"ragents": {
|
|
6
|
+
"title": "Notebook",
|
|
7
|
+
"description": "Keeps the notes that run scripts send it, newest first.",
|
|
8
|
+
"backend": "src/server.ts",
|
|
9
|
+
"views": [
|
|
10
|
+
{
|
|
11
|
+
"id": "main",
|
|
12
|
+
"client": "src/client.tsx"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
import { context, useAppState } from "@ragents/client";
|
|
4
|
+
import * as UI from "@ragents/client/ui";
|
|
5
|
+
|
|
6
|
+
const App = () => {
|
|
7
|
+
const state = useAppState();
|
|
8
|
+
const notes = state.notes ?? [];
|
|
9
|
+
const [status, setStatus] = React.useState("Run scripts add their notes here.");
|
|
10
|
+
|
|
11
|
+
const clear = async (): Promise<void> => {
|
|
12
|
+
const answer = await context.capabilities.call("clear", {});
|
|
13
|
+
setStatus(`Cleared ${answer.cleared} ${answer.cleared === 1 ? "note" : "notes"}.`);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<UI.AppLayout title="Notebook" description={<>{notes.length} {notes.length === 1 ? "note" : "notes"}</>}>
|
|
18
|
+
<UI.Stack>
|
|
19
|
+
<p className="text-muted-foreground" role="status">{status}</p>
|
|
20
|
+
<ul className="border-t border-border">
|
|
21
|
+
{notes.map((note, index) => <li className="min-h-8 border-b border-border-soft py-1.5 [overflow-wrap:anywhere]" key={index}>{note}</li>)}
|
|
22
|
+
</ul>
|
|
23
|
+
<UI.Button disabled={notes.length === 0} onClick={() => void clear()} variant="outline">Clear</UI.Button>
|
|
24
|
+
</UI.Stack>
|
|
25
|
+
</UI.AppLayout>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const root = document.getElementById("root");
|
|
30
|
+
if (!root) throw new Error("The #root element is missing.");
|
|
31
|
+
createRoot(root).render(<App />);
|