@zetaloop/chappie 0.4.1 → 1.0.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,56 @@
1
+ import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
2
+ import {
3
+ historyPage,
4
+ historyResult
5
+ } from "./chunk-GWYP7B66.js";
6
+
7
+ // src/journal.ts
8
+ function journalHistory(branch, sessionId, range) {
9
+ const page = historyPage(branch, range, (entry) => {
10
+ switch (entry.type) {
11
+ case "message": {
12
+ const message = entry.message;
13
+ return message.customType !== "chappie.request";
14
+ }
15
+ case "custom_message":
16
+ return entry.customType !== "chappie.request";
17
+ case "custom":
18
+ return entry.customType === "chappie.notice" && entry.data?.event !== "history";
19
+ case "compaction":
20
+ case "branch_summary":
21
+ return true;
22
+ default:
23
+ return false;
24
+ }
25
+ });
26
+ const sources = /* @__PURE__ */ new Map();
27
+ for (const entry of branch) {
28
+ if (entry.type !== "message") continue;
29
+ const message = entry.message;
30
+ if (message.role !== "assistant" || !message.chappie) continue;
31
+ for (const block of message.content) {
32
+ if (block.type === "toolCall") sources.set(block.id, message.chappie);
33
+ }
34
+ }
35
+ return historyResult(
36
+ {
37
+ ...page,
38
+ entries: page.entries.map((entry) => {
39
+ const { message: value, ...record } = entry;
40
+ if (entry.type !== "message") return record;
41
+ const message = value;
42
+ const source = message.role === "toolResult" && typeof message.toolCallId === "string" ? sources.get(message.toolCallId) : void 0;
43
+ return {
44
+ ...message,
45
+ ...record,
46
+ ...source ? { chappie: source } : {}
47
+ };
48
+ })
49
+ },
50
+ sessionId
51
+ );
52
+ }
53
+
54
+ export {
55
+ journalHistory
56
+ };
@@ -0,0 +1,94 @@
1
+ import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
9
+ var __typeError = (msg) => {
10
+ throw TypeError(msg);
11
+ };
12
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
13
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
14
+ }) : x)(function(x) {
15
+ if (typeof require !== "undefined") return require.apply(this, arguments);
16
+ throw Error('Dynamic require of "' + x + '" is not supported');
17
+ });
18
+ var __commonJS = (cb, mod) => function __require2() {
19
+ try {
20
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
21
+ } catch (e) {
22
+ throw mod = 0, e;
23
+ }
24
+ };
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __using = (stack, value, async) => {
46
+ if (value != null) {
47
+ if (typeof value !== "object" && typeof value !== "function") __typeError("Object expected");
48
+ var dispose, inner;
49
+ if (async) dispose = value[__knownSymbol("asyncDispose")];
50
+ if (dispose === void 0) {
51
+ dispose = value[__knownSymbol("dispose")];
52
+ if (async) inner = dispose;
53
+ }
54
+ if (typeof dispose !== "function") __typeError("Object not disposable");
55
+ if (inner) dispose = function() {
56
+ try {
57
+ inner.call(this);
58
+ } catch (e) {
59
+ return Promise.reject(e);
60
+ }
61
+ };
62
+ stack.push([async, dispose, value]);
63
+ } else if (async) {
64
+ stack.push([async]);
65
+ }
66
+ return value;
67
+ };
68
+ var __callDispose = (stack, error, hasError) => {
69
+ var E = typeof SuppressedError === "function" ? SuppressedError : function(e, s, m, _) {
70
+ return _ = Error(m), _.name = "SuppressedError", _.error = e, _.suppressed = s, _;
71
+ };
72
+ var fail = (e) => error = hasError ? new E(e, error, "An error was suppressed during disposal") : (hasError = true, e);
73
+ var next = (it) => {
74
+ while (it = stack.pop()) {
75
+ try {
76
+ var result = it[1] && it[1].call(it[2]);
77
+ if (it[0]) return Promise.resolve(result).then(next, (e) => (fail(e), next()));
78
+ } catch (e) {
79
+ fail(e);
80
+ }
81
+ }
82
+ if (hasError) throw error;
83
+ };
84
+ return next();
85
+ };
86
+
87
+ export {
88
+ __require,
89
+ __commonJS,
90
+ __export,
91
+ __toESM,
92
+ __using,
93
+ __callDispose
94
+ };
package/dist/cli.js ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
3
+ import {
4
+ package_default
5
+ } from "./chunk-DN7OHZK6.js";
6
+ import "./chunk-UOFCCHBS.js";
7
+
8
+ // src/cli.ts
9
+ import { parseArgs } from "node:util";
10
+ var { values, positionals } = parseArgs({
11
+ allowPositionals: true,
12
+ options: {
13
+ help: { type: "boolean", short: "h" },
14
+ version: { type: "boolean", short: "v" },
15
+ provider: { type: "boolean" },
16
+ chatgpt: { type: "boolean" }
17
+ }
18
+ });
19
+ if (values.help) {
20
+ console.log(
21
+ "Usage: chappie [codex]\n\nRun the broker and ChatGPT MCP server.\nThe codex command runs the installed Codex plugin."
22
+ );
23
+ } else if (values.version) {
24
+ console.log(package_default.version);
25
+ } else {
26
+ try {
27
+ if (positionals.length === 1 && positionals[0] === "codex") {
28
+ if (values.provider) {
29
+ const { serveCodex } = await import("./codex-RI2XL4HV.js");
30
+ await serveCodex();
31
+ } else {
32
+ const { serveCodexPlugin } = await import("./codex-plugin-NSKWB3WS.js");
33
+ await serveCodexPlugin(values.chatgpt);
34
+ }
35
+ } else if (positionals.length === 0 && !values.provider && !values.chatgpt) {
36
+ const { serve } = await import("./stdio-KJVCYPXJ.js");
37
+ await serve();
38
+ } else {
39
+ throw new Error("Usage: chappie [codex]");
40
+ }
41
+ } catch (error) {
42
+ const message = error instanceof Error ? error.message : String(error);
43
+ console.error(message);
44
+ process.send?.({ error: message });
45
+ process.exitCode = 1;
46
+ }
47
+ }