@7n/tauri-components 0.0.1 → 0.1.1
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/package.json +12 -2
- package/types/core/agent-handler.d.ts +43 -0
- package/types/core/agent-kit.d.ts +30 -0
- package/types/core/dispatch.d.ts +14 -0
- package/types/core/llm.d.ts +52 -0
- package/types/core/manifest.d.ts +26 -0
- package/types/core/scope.d.ts +35 -0
- package/types/core/tools.d.ts +7 -0
- package/types/index.d.ts +7 -0
package/package.json
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@7n/tauri-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shared LLM agent engine + Vue/Quasar UI for Tauri apps (chat, journal, trust-tier approval).",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/nitra/tauri-components.git",
|
|
10
|
+
"directory": "npm"
|
|
11
|
+
},
|
|
7
12
|
"publishConfig": {
|
|
8
13
|
"access": "public"
|
|
9
14
|
},
|
|
15
|
+
"types": "./types/index.d.ts",
|
|
10
16
|
"exports": {
|
|
11
|
-
".":
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./types/index.d.ts",
|
|
19
|
+
"default": "./src/index.js"
|
|
20
|
+
},
|
|
12
21
|
"./vue": "./src/vue/index.js",
|
|
13
22
|
"./components": "./src/components/index.js"
|
|
14
23
|
},
|
|
15
24
|
"files": [
|
|
16
25
|
"src",
|
|
26
|
+
"types",
|
|
17
27
|
"!**/*.test.*",
|
|
18
28
|
"!**/*.spec.*",
|
|
19
29
|
"!**/__tests__/**",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Start a new agent request.
|
|
3
|
+
* @param {{ intent: string, actor: object, chat: Function, dispatch: Function, journal: object, tools: object[], gate: Function, buildSystem?: Function, grounding?: object }} opts request parameters
|
|
4
|
+
* @returns {Promise<object>} structured result envelope
|
|
5
|
+
*/
|
|
6
|
+
export function handleRequest({ intent, actor, chat, dispatch, journal, tools, gate, buildSystem, grounding }: {
|
|
7
|
+
intent: string;
|
|
8
|
+
actor: object;
|
|
9
|
+
chat: Function;
|
|
10
|
+
dispatch: Function;
|
|
11
|
+
journal: object;
|
|
12
|
+
tools: object[];
|
|
13
|
+
gate: Function;
|
|
14
|
+
buildSystem?: Function;
|
|
15
|
+
grounding?: object;
|
|
16
|
+
}): Promise<object>;
|
|
17
|
+
/**
|
|
18
|
+
* Resume a conversation with a follow-up / clarification answer.
|
|
19
|
+
* @param {{ requestId: string, message: string, actor: object, chat: Function, dispatch: Function, journal: object, tools: object[], gate: Function }} opts resume parameters
|
|
20
|
+
* @returns {Promise<object>} updated result envelope
|
|
21
|
+
*/
|
|
22
|
+
export function handleRespond({ requestId, message, chat, dispatch, journal, tools, gate }: {
|
|
23
|
+
requestId: string;
|
|
24
|
+
message: string;
|
|
25
|
+
actor: object;
|
|
26
|
+
chat: Function;
|
|
27
|
+
dispatch: Function;
|
|
28
|
+
journal: object;
|
|
29
|
+
tools: object[];
|
|
30
|
+
gate: Function;
|
|
31
|
+
}): Promise<object>;
|
|
32
|
+
/**
|
|
33
|
+
* Approve (or reject) a pending destructive action. Executes with the approver's
|
|
34
|
+
* (human) authority via the injected dispatch — no gate.
|
|
35
|
+
* @param {{ requestId: string, approve: boolean, dispatch: Function, journal: object }} opts approval parameters
|
|
36
|
+
* @returns {Promise<object>} updated result envelope
|
|
37
|
+
*/
|
|
38
|
+
export function handleApprove({ requestId, approve, dispatch, journal }: {
|
|
39
|
+
requestId: string;
|
|
40
|
+
approve: boolean;
|
|
41
|
+
dispatch: Function;
|
|
42
|
+
journal: object;
|
|
43
|
+
}): Promise<object>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {object} config kit configuration
|
|
3
|
+
* @param {object[]} config.catalog tool definitions (required)
|
|
4
|
+
* @param {string|((ctx: object) => string)} [config.systemPrompt] domain system prompt (or builder from grounding ctx)
|
|
5
|
+
* @param {(tool: object, input: object) => unknown} [config.transport] backend runner; omit to build the kit without dispatch (manifest/scope only)
|
|
6
|
+
* @param {object} [config.journal] journal store { create, load, update, list }
|
|
7
|
+
* @param {Record<string, number>} [config.actorTiers] max executable tier rank per actor kind
|
|
8
|
+
* @param {{ tool: string, key?: string, fallback?: unknown }} [config.grounding] optional read tool to ground the prompt
|
|
9
|
+
* @returns {{ dispatch: Function|null, classify: Function, scopedManifest: Function, toolManifest: Function, request: Function, respond: Function, approve: Function }} bound kit
|
|
10
|
+
*/
|
|
11
|
+
export function createAgentKit({ catalog, systemPrompt, transport, journal, actorTiers, grounding }?: {
|
|
12
|
+
catalog: object[];
|
|
13
|
+
systemPrompt?: string | ((ctx: object) => string) | undefined;
|
|
14
|
+
transport?: ((tool: object, input: object) => unknown) | undefined;
|
|
15
|
+
journal?: object | undefined;
|
|
16
|
+
actorTiers?: Record<string, number> | undefined;
|
|
17
|
+
grounding?: {
|
|
18
|
+
tool: string;
|
|
19
|
+
key?: string;
|
|
20
|
+
fallback?: unknown;
|
|
21
|
+
} | undefined;
|
|
22
|
+
}): {
|
|
23
|
+
dispatch: Function | null;
|
|
24
|
+
classify: Function;
|
|
25
|
+
scopedManifest: Function;
|
|
26
|
+
toolManifest: Function;
|
|
27
|
+
request: Function;
|
|
28
|
+
respond: Function;
|
|
29
|
+
approve: Function;
|
|
30
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate an input object against a tool's schema and custom validator.
|
|
3
|
+
* @param {object} tool tool definition
|
|
4
|
+
* @param {object} [input] candidate input
|
|
5
|
+
* @returns {string|null} error message, or null when valid
|
|
6
|
+
*/
|
|
7
|
+
export function validateInput(tool: object, input?: object): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Build a dispatch function bound to a catalog and a transport.
|
|
10
|
+
* @param {object[]} catalog tool definitions
|
|
11
|
+
* @param {(tool: object, input: object) => unknown} transport runs the tool's backend call
|
|
12
|
+
* @returns {(name: string, input?: object) => Promise<object>} dispatch returning an envelope
|
|
13
|
+
*/
|
|
14
|
+
export function createDispatch(catalog: object[], transport: (tool: object, input: object) => unknown): (name: string, input?: object) => Promise<object>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run the tool-calling loop until the model answers without a tool call.
|
|
3
|
+
* Accepts either a fresh prompt or an existing messages[] for sessional resume.
|
|
4
|
+
* @param {object} params loop parameters
|
|
5
|
+
* @param {string} [params.prompt] user request (fresh start)
|
|
6
|
+
* @param {object[]} [params.messages] existing conversation to resume (takes priority over prompt)
|
|
7
|
+
* @param {(name: string, input: object) => Promise<object>} params.dispatch tool dispatcher returning an envelope
|
|
8
|
+
* @param {(req: {messages: object[], tools: object[]}) => Promise<object>} params.chat model call returning an assistant message
|
|
9
|
+
* @param {number} [params.maxSteps] safety cap on loop iterations
|
|
10
|
+
* @param {string} [params.system] system prompt (only used when building fresh from prompt)
|
|
11
|
+
* @param {object[]} [params.tools] LLM tool manifest (pass a scoped manifest to restrict)
|
|
12
|
+
* @param {(name: string) => 'allow'|'approval'|'deny'} [params.gate] per-call decision (default: allow)
|
|
13
|
+
* @returns {Promise<{content: string, steps: number, trace: object[], messages: object[], stopped?: string, pendingApproval?: object}>} loop result
|
|
14
|
+
*/
|
|
15
|
+
export function runAgent({ prompt, messages: initialMessages, dispatch, chat, maxSteps, system, tools, gate }: {
|
|
16
|
+
prompt?: string | undefined;
|
|
17
|
+
messages?: object[] | undefined;
|
|
18
|
+
dispatch: (name: string, input: object) => Promise<object>;
|
|
19
|
+
chat: (req: {
|
|
20
|
+
messages: object[];
|
|
21
|
+
tools: object[];
|
|
22
|
+
}) => Promise<object>;
|
|
23
|
+
maxSteps?: number | undefined;
|
|
24
|
+
system?: string | undefined;
|
|
25
|
+
tools?: object[] | undefined;
|
|
26
|
+
gate?: ((name: string) => "allow" | "approval" | "deny") | undefined;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
content: string;
|
|
29
|
+
steps: number;
|
|
30
|
+
trace: object[];
|
|
31
|
+
messages: object[];
|
|
32
|
+
stopped?: string;
|
|
33
|
+
pendingApproval?: object;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Build a `chat` function that calls an OpenAI-compatible endpoint (omlx).
|
|
37
|
+
* @param {object} params config
|
|
38
|
+
* @param {string} params.baseUrl base URL incl. /v1 (e.g. http://127.0.0.1:10240/v1)
|
|
39
|
+
* @param {string} params.model served model id
|
|
40
|
+
* @param {string} [params.apiKey] optional bearer token
|
|
41
|
+
* @param {typeof fetch} [params.fetchFn] fetch implementation (injectable for tests / tauri-http)
|
|
42
|
+
* @returns {(req: {messages: object[], tools: object[]}) => Promise<object>} chat function
|
|
43
|
+
*/
|
|
44
|
+
export function createOpenAiChat({ baseUrl, model, apiKey, fetchFn }: {
|
|
45
|
+
baseUrl: string;
|
|
46
|
+
model: string;
|
|
47
|
+
apiKey?: string | undefined;
|
|
48
|
+
fetchFn?: typeof fetch | undefined;
|
|
49
|
+
}): (req: {
|
|
50
|
+
messages: object[];
|
|
51
|
+
tools: object[];
|
|
52
|
+
}) => Promise<object>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a tool input spec into a JSON Schema object.
|
|
3
|
+
* @param {Record<string, {type: string, required?: boolean, description?: string}>} input tool input spec
|
|
4
|
+
* @returns {object} JSON Schema for the parameters object
|
|
5
|
+
*/
|
|
6
|
+
export function toJsonSchema(input: Record<string, {
|
|
7
|
+
type: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
description?: string;
|
|
10
|
+
}>): object;
|
|
11
|
+
/**
|
|
12
|
+
* OpenAI function-calling tool definitions, optionally filtered (e.g. by scope).
|
|
13
|
+
* @param {object[]} catalog tool definitions
|
|
14
|
+
* @param {(tool: object) => boolean} [allow] predicate; default includes all tools
|
|
15
|
+
* @returns {object[]} OpenAI `tools` array
|
|
16
|
+
*/
|
|
17
|
+
export function toolManifest(catalog: object[], allow?: (tool: object) => boolean): object[];
|
|
18
|
+
/**
|
|
19
|
+
* Compact catalog listing (name + summary).
|
|
20
|
+
* @param {object[]} catalog tool definitions
|
|
21
|
+
* @returns {{name: string, summary: string}[]} tool list
|
|
22
|
+
*/
|
|
23
|
+
export function listTools(catalog: object[]): {
|
|
24
|
+
name: string;
|
|
25
|
+
summary: string;
|
|
26
|
+
}[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classify a tool call for an actor.
|
|
3
|
+
* @param {object[]} catalog tool definitions
|
|
4
|
+
* @param {Record<string, number>|undefined} actorTiers max executable tier rank per actor kind
|
|
5
|
+
* @param {{ kind?: string }} actor caller identity
|
|
6
|
+
* @param {string} toolName tool name
|
|
7
|
+
* @returns {'allow'|'approval'|'deny'} decision
|
|
8
|
+
*/
|
|
9
|
+
export function classify(catalog: object[], actorTiers: Record<string, number> | undefined, actor: {
|
|
10
|
+
kind?: string;
|
|
11
|
+
}, toolName: string): "allow" | "approval" | "deny";
|
|
12
|
+
/**
|
|
13
|
+
* LLM tool manifest visible to the actor (everything it may run OR request approval for).
|
|
14
|
+
* @param {object[]} catalog tool definitions
|
|
15
|
+
* @param {Record<string, number>|undefined} actorTiers max executable tier rank per actor kind
|
|
16
|
+
* @param {{ kind?: string }} actor caller identity
|
|
17
|
+
* @returns {object[]} OpenAI tools array
|
|
18
|
+
*/
|
|
19
|
+
export function scopedManifest(catalog: object[], actorTiers: Record<string, number> | undefined, actor: {
|
|
20
|
+
kind?: string;
|
|
21
|
+
}): object[];
|
|
22
|
+
/**
|
|
23
|
+
* Tool names visible to the actor.
|
|
24
|
+
* @param {object[]} catalog tool definitions
|
|
25
|
+
* @param {Record<string, number>|undefined} actorTiers max executable tier rank per actor kind
|
|
26
|
+
* @param {{ kind?: string }} actor caller identity
|
|
27
|
+
* @returns {string[]} visible tool names
|
|
28
|
+
*/
|
|
29
|
+
export function scopedToolNames(catalog: object[], actorTiers: Record<string, number> | undefined, actor: {
|
|
30
|
+
kind?: string;
|
|
31
|
+
}): string[];
|
|
32
|
+
export namespace DEFAULT_ACTOR_TIERS {
|
|
33
|
+
let human: number;
|
|
34
|
+
let agent: number;
|
|
35
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Look up a tool by name in a catalog.
|
|
3
|
+
* @param {object[]} catalog tool definitions
|
|
4
|
+
* @param {string} name tool name
|
|
5
|
+
* @returns {object|null} the tool definition, or null if unknown
|
|
6
|
+
*/
|
|
7
|
+
export function getTool(catalog: object[], name: string): object | null;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createAgentKit } from "./core/agent-kit.js";
|
|
2
|
+
export { getTool } from "./core/tools.js";
|
|
3
|
+
export { handleApprove, handleRequest, handleRespond } from "./core/agent-handler.js";
|
|
4
|
+
export { createDispatch, validateInput } from "./core/dispatch.js";
|
|
5
|
+
export { createOpenAiChat, runAgent } from "./core/llm.js";
|
|
6
|
+
export { listTools, toJsonSchema, toolManifest } from "./core/manifest.js";
|
|
7
|
+
export { classify, DEFAULT_ACTOR_TIERS, scopedManifest, scopedToolNames } from "./core/scope.js";
|