@cxyhhhhh/qraft-plugin-ai-chat 0.0.0-stage → 0.1.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.
@@ -0,0 +1,8 @@
1
+ import { type PluginDefinition } from "@cxyhhhhh/qraft-core";
2
+ import type { ChatResponse } from "@cxyhhhhh/qraft-pack-ai";
3
+ import { PACK_ID as AI_PACK_ID } from "@cxyhhhhh/qraft-pack-ai";
4
+ export declare const PLUGIN_ID: "@cxyhhhhh/qraft-plugin-ai-chat";
5
+ export declare function aiChatPlugin(): PluginDefinition;
6
+ export { AI_PACK_ID };
7
+ export type { ChatResponse };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,gBAAgB,EAAgB,MAAM,aAAa,CAAC;AAChF,OAAO,KAAK,EAA0B,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AACzF,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEvD,eAAO,MAAM,SAAS,EAAG,uBAAgC,CAAC;AAE1D,wBAAgB,YAAY,IAAI,gBAAgB,CA4B/C;AAED,OAAO,EAAE,UAAU,EAAE,CAAC;AAoCtB,YAAY,EAAE,YAAY,EAAE,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,66 @@
1
+ import { definePlugin } from "@cxyhhhhh/qraft-core";
2
+ import { PACK_ID as AI_PACK_ID } from "@cxyhhhhh/qraft-pack-ai";
3
+ export const PLUGIN_ID = "@cxyhhhhh/qraft-plugin-ai-chat";
4
+ export function aiChatPlugin() {
5
+ return definePlugin({
6
+ manifest: {
7
+ id: PLUGIN_ID,
8
+ description: "Fallback chat",
9
+ permissions: ["command.register", "service.inject"],
10
+ requires: ["ai.model", "ai.memory", "ai.tools"],
11
+ },
12
+ setup(ctx) {
13
+ const model = ctx.services.inject("ai.model");
14
+ const memory = ctx.services.inject("ai.memory");
15
+ const tools = ctx.services.inject("ai.tools");
16
+ ctx.router.register({
17
+ kind: "fallback",
18
+ async handler(event) {
19
+ const session = event.session;
20
+ if (!session || !session.text.trim())
21
+ return false;
22
+ if (event.signal?.aborted)
23
+ return;
24
+ await memory.append(session.sessionKey, { role: "user", content: session.text });
25
+ const history = await memory.load(session.sessionKey);
26
+ const text = await answer(model, tools, history, session.sessionKey, event.signal);
27
+ if (event.signal?.aborted)
28
+ return;
29
+ await writeReply(session, text);
30
+ await memory.append(session.sessionKey, { role: "assistant", content: text });
31
+ },
32
+ });
33
+ },
34
+ });
35
+ }
36
+ export { AI_PACK_ID };
37
+ async function answer(model, tools, history, sessionKey, signal) {
38
+ const available = tools.list();
39
+ if (available.length === 0 && model.stream) {
40
+ let full = "";
41
+ for await (const delta of model.stream({ messages: history, signal })) {
42
+ if (signal?.aborted)
43
+ return full;
44
+ full += delta;
45
+ }
46
+ return full;
47
+ }
48
+ let response = await model.complete({ messages: history, tools: available, signal });
49
+ if (signal?.aborted || !response.toolCalls?.length)
50
+ return response.text;
51
+ const messages = [...history];
52
+ for (const call of response.toolCalls) {
53
+ if (signal?.aborted)
54
+ return response.text;
55
+ const output = await tools.invoke(call.name, call.arguments, { sessionKey });
56
+ messages.push({ role: "tool", content: output, name: call.name });
57
+ }
58
+ response = await model.complete({ messages, signal });
59
+ return response.text;
60
+ }
61
+ async function writeReply(session, text) {
62
+ const stream = session.stream();
63
+ await stream.write(text);
64
+ await stream.end();
65
+ }
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuC,MAAM,aAAa,CAAC;AAEhF,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,CAAC,MAAM,SAAS,GAAG,uBAAgC,CAAC;A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AC1C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;QAC7E,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACpE,CAAC;IACD,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IACtD,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,OAAgB,EAAE,IAAY;IACtD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAChC,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzB,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;AACrB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
1
  {
2
2
  "name": "@cxyhhhhh/qraft-plugin-ai-chat",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Fallback chat plugin that consumes the AI pack.",
5
+ "type": "module",
6
+ "files": ["dist"],
7
+ "publishConfig": { "access": "public" },
8
+ "engines": { "node": ">=22.5" },
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.json",
19
+ "typecheck": "tsc -p tsconfig.json --noEmit"
20
+ },
21
+ "dependencies": {
22
+ "@cxyhhhhh/qraft-core": "0.1.0",
23
+ "@cxyhhhhh/qraft-pack-ai": "0.1.0"
24
+ }
25
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.