@skaile/forge-app-actions 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -2
- package/dist/module.d.mts +23 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +37 -0
- package/dist/runtime/chat/index.d.ts +52 -0
- package/dist/runtime/chat/index.js +100 -0
- package/dist/runtime/chat/server.d.ts +36 -0
- package/dist/runtime/chat/server.js +27 -0
- package/dist/runtime/chat/types.d.ts +10 -0
- package/dist/runtime/chat/types.js +0 -0
- package/dist/runtime/client-capabilities.d.ts +29 -0
- package/dist/runtime/client-capabilities.js +25 -0
- package/dist/runtime/components-nuxt-ui/ForgeCapabilityApproval.d.vue.ts +2 -0
- package/dist/runtime/components-nuxt-ui/ForgeCapabilityApproval.vue +125 -0
- package/dist/runtime/components-nuxt-ui/ForgeCapabilityApproval.vue.d.ts +2 -0
- package/dist/runtime/components-nuxt-ui/ForgeCommandPalette.d.vue.ts +2 -0
- package/dist/runtime/components-nuxt-ui/ForgeCommandPalette.vue +218 -0
- package/dist/runtime/components-nuxt-ui/ForgeCommandPalette.vue.d.ts +2 -0
- package/dist/runtime/composables/defineClientCapability.d.ts +64 -0
- package/dist/runtime/composables/defineClientCapability.js +40 -0
- package/dist/runtime/composables/defineForgeAction.d.ts +82 -0
- package/dist/runtime/composables/defineForgeAction.js +147 -0
- package/dist/runtime/composables/useAgentCapabilities.d.ts +78 -0
- package/dist/runtime/composables/useAgentCapabilities.js +94 -0
- package/dist/runtime/composables/useCapabilityApproval.d.ts +109 -0
- package/dist/runtime/composables/useCapabilityApproval.js +74 -0
- package/dist/runtime/composables/useCapabilityInvocations.d.ts +150 -0
- package/dist/runtime/composables/useCapabilityInvocations.js +118 -0
- package/dist/runtime/composables/useCommandPalette.d.ts +28 -0
- package/dist/runtime/composables/useCommandPalette.js +49 -0
- package/dist/runtime/composables/usePaletteArgStep.d.ts +47 -0
- package/dist/runtime/composables/usePaletteArgStep.js +51 -0
- package/dist/runtime/internal/describe-error.d.ts +10 -0
- package/dist/runtime/internal/describe-error.js +12 -0
- package/dist/runtime/server/index.d.ts +7 -0
- package/dist/runtime/server/index.js +2 -0
- package/dist/runtime/server/utils/capability-registry.d.ts +35 -0
- package/dist/runtime/server/utils/capability-registry.js +24 -0
- package/dist/runtime/server/utils/client-capability-bridge.d.ts +647 -0
- package/dist/runtime/server/utils/client-capability-bridge.js +755 -0
- package/dist/runtime/shims-vue.d.ts +8 -0
- package/dist/runtime/types/client-capability.d.ts +159 -0
- package/dist/runtime/types/client-capability.js +0 -0
- package/dist/runtime/types/command-palette.d.ts +75 -0
- package/dist/runtime/types/command-palette.js +0 -0
- package/dist/runtime/types/forge-action.d.ts +152 -0
- package/dist/runtime/types/forge-action.js +0 -0
- package/dist/runtime/types/index.d.ts +3 -0
- package/dist/runtime/types/index.js +0 -0
- package/dist/types.d.mts +9 -0
- package/package.json +94 -4
- package/src/runtime/chat/index.ts +190 -0
- package/src/runtime/chat/server.ts +64 -0
- package/src/runtime/chat/types.ts +13 -0
- package/src/runtime/client-capabilities.ts +82 -0
- package/src/runtime/components-nuxt-ui/ForgeCapabilityApproval.vue +240 -0
- package/src/runtime/components-nuxt-ui/ForgeCommandPalette.vue +363 -0
- package/src/runtime/composables/defineClientCapability.ts +119 -0
- package/src/runtime/composables/defineForgeAction.ts +278 -0
- package/src/runtime/composables/useAgentCapabilities.ts +215 -0
- package/src/runtime/composables/useCapabilityApproval.ts +219 -0
- package/src/runtime/composables/useCapabilityInvocations.ts +325 -0
- package/src/runtime/composables/useCommandPalette.ts +97 -0
- package/src/runtime/composables/usePaletteArgStep.ts +110 -0
- package/src/runtime/internal/describe-error.ts +21 -0
- package/src/runtime/server/index.ts +8 -0
- package/src/runtime/server/utils/capability-registry.ts +66 -0
- package/src/runtime/server/utils/client-capability-bridge.ts +1201 -0
- package/src/runtime/shims-vue.d.ts +8 -0
- package/src/runtime/types/client-capability.ts +178 -0
- package/src/runtime/types/command-palette.ts +78 -0
- package/src/runtime/types/forge-action.ts +166 -0
- package/src/runtime/types/index.ts +24 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { computed, ref, shallowRef } from "vue";
|
|
2
|
+
export function usePaletteArgStep() {
|
|
3
|
+
const action = shallowRef(null);
|
|
4
|
+
const options = shallowRef([]);
|
|
5
|
+
const loading = ref(false);
|
|
6
|
+
let ticket = 0;
|
|
7
|
+
const active = computed(() => action.value !== null);
|
|
8
|
+
const prompt = computed(() => action.value?.arg ?? null);
|
|
9
|
+
function begin(next) {
|
|
10
|
+
if (!next.arg) return false;
|
|
11
|
+
action.value = next;
|
|
12
|
+
options.value = [];
|
|
13
|
+
void query("");
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
async function query(text) {
|
|
17
|
+
const arg = action.value?.arg;
|
|
18
|
+
if (!arg?.options) {
|
|
19
|
+
options.value = [];
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const mine = ++ticket;
|
|
23
|
+
loading.value = true;
|
|
24
|
+
try {
|
|
25
|
+
const found = await arg.options(text);
|
|
26
|
+
if (mine !== ticket) return;
|
|
27
|
+
options.value = found;
|
|
28
|
+
} catch {
|
|
29
|
+
if (mine === ticket) options.value = [];
|
|
30
|
+
} finally {
|
|
31
|
+
if (mine === ticket) loading.value = false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function cancel() {
|
|
35
|
+
ticket++;
|
|
36
|
+
action.value = null;
|
|
37
|
+
options.value = [];
|
|
38
|
+
loading.value = false;
|
|
39
|
+
}
|
|
40
|
+
function valueFor(typed, index) {
|
|
41
|
+
const arg = action.value?.arg;
|
|
42
|
+
if (!arg) return null;
|
|
43
|
+
const picked = options.value[index];
|
|
44
|
+
if (picked) return picked.value;
|
|
45
|
+
const allowCustom = arg.allowCustom ?? !arg.options;
|
|
46
|
+
const trimmed = typed.trim();
|
|
47
|
+
if (allowCustom && trimmed.length > 0) return trimmed;
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return { action, options, loading, active, prompt, begin, query, cancel, valueFor };
|
|
51
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn a thrown value into the single line the agent (or model) will read.
|
|
3
|
+
*
|
|
4
|
+
* A zod v4 error carries the useful part in `issues`; `err.message` alone is a
|
|
5
|
+
* JSON blob. Flatten it to `path: message` pairs so the model can act on it.
|
|
6
|
+
*
|
|
7
|
+
* Lives outside `composables/` on purpose: that directory is auto-imported by
|
|
8
|
+
* the Nuxt module, and this helper is internal.
|
|
9
|
+
*/
|
|
10
|
+
export declare function describeError(err: unknown): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function describeError(err) {
|
|
2
|
+
if (err && typeof err === "object" && Array.isArray(err.issues)) {
|
|
3
|
+
const issues = err.issues;
|
|
4
|
+
const lines = issues.map((issue) => {
|
|
5
|
+
const path = Array.isArray(issue.path) ? issue.path.join(".") : "";
|
|
6
|
+
return path ? `${path}: ${issue.message}` : String(issue.message);
|
|
7
|
+
});
|
|
8
|
+
if (lines.length > 0) return lines.join("; ");
|
|
9
|
+
}
|
|
10
|
+
if (err instanceof Error) return err.message;
|
|
11
|
+
return String(err);
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Explicit entry point for the server-side client-capability bridge, via the
|
|
3
|
+
* `./server` subpath. In a Nuxt consumer the same symbols are auto-imported
|
|
4
|
+
* (the module's `addServerImportsDir` on `runtime/server/utils`).
|
|
5
|
+
*/
|
|
6
|
+
export * from "./utils/capability-registry.js";
|
|
7
|
+
export * from "./utils/client-capability-bridge.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AgentEvent, Capability } from "@skaile/workspaces/sdk/types";
|
|
2
|
+
/** Event sink handed to a capability handler when it runs. */
|
|
3
|
+
export interface CapabilityHandlerCtx {
|
|
4
|
+
/** Emit a synthetic AgentEvent into the app's SSE stream. */
|
|
5
|
+
emitEvent: (event: AgentEvent) => void;
|
|
6
|
+
}
|
|
7
|
+
export type CapabilityHandler = (input: Record<string, unknown>, ctx: CapabilityHandlerCtx) => Promise<unknown>;
|
|
8
|
+
export interface CapabilityEntry {
|
|
9
|
+
capability: Capability;
|
|
10
|
+
handler: CapabilityHandler;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Plain-TS capability registry for the forge app — holds client-side v2
|
|
14
|
+
* capabilities and routes `capability_invoked` calls to their handlers.
|
|
15
|
+
*/
|
|
16
|
+
export declare class CapabilityRegistry {
|
|
17
|
+
private entries;
|
|
18
|
+
register(entry: CapabilityEntry): void;
|
|
19
|
+
list(): Capability[];
|
|
20
|
+
dispatch(name: string, input: Record<string, unknown>, ctx: CapabilityHandlerCtx): Promise<unknown | {
|
|
21
|
+
error: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/** Dispatch a `capability_invoked` event and send back its `capability_result`. */
|
|
25
|
+
export declare function handleCapabilityInvoked(event: {
|
|
26
|
+
callId: string;
|
|
27
|
+
name: string;
|
|
28
|
+
input: unknown;
|
|
29
|
+
}, deps: {
|
|
30
|
+
registry: CapabilityRegistry;
|
|
31
|
+
ctx: CapabilityHandlerCtx;
|
|
32
|
+
sendResult: (callId: string, result: unknown) => Promise<void> | void;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
/** Process-wide singleton — capabilities are registered once at module load. */
|
|
35
|
+
export declare const capabilityRegistry: CapabilityRegistry;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class CapabilityRegistry {
|
|
2
|
+
entries = /* @__PURE__ */ new Map();
|
|
3
|
+
register(entry) {
|
|
4
|
+
this.entries.set(entry.capability.name, entry);
|
|
5
|
+
}
|
|
6
|
+
list() {
|
|
7
|
+
return [...this.entries.values()].map((e) => e.capability);
|
|
8
|
+
}
|
|
9
|
+
async dispatch(name, input, ctx) {
|
|
10
|
+
const entry = this.entries.get(name);
|
|
11
|
+
if (!entry) return { error: `Unknown capability: ${name}` };
|
|
12
|
+
try {
|
|
13
|
+
return await entry.handler(input, ctx);
|
|
14
|
+
} catch (err) {
|
|
15
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export async function handleCapabilityInvoked(event, deps) {
|
|
20
|
+
const input = event.input && typeof event.input === "object" ? event.input : {};
|
|
21
|
+
const result = await deps.registry.dispatch(event.name, input, deps.ctx);
|
|
22
|
+
await deps.sendResult(event.callId, result);
|
|
23
|
+
}
|
|
24
|
+
export const capabilityRegistry = new CapabilityRegistry();
|