@averagejoeslab/puppuccino-sdk 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.
- package/dist/index.cjs +193 -0
- package/dist/index.js +176 -0
- package/package.json +35 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
PuppuccinoClient: () => PuppuccinoClient,
|
|
24
|
+
createClient: () => createClient,
|
|
25
|
+
query: () => query
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_puppuccino_core = require("@averagejoeslab/puppuccino-core");
|
|
29
|
+
var PuppuccinoClient = class {
|
|
30
|
+
config;
|
|
31
|
+
provider;
|
|
32
|
+
tools;
|
|
33
|
+
sessionManager;
|
|
34
|
+
hooks;
|
|
35
|
+
permissions;
|
|
36
|
+
constructor(config) {
|
|
37
|
+
this.config = (0, import_puppuccino_core.loadConfig)();
|
|
38
|
+
if (config) {
|
|
39
|
+
this.config = { ...this.config, ...config };
|
|
40
|
+
}
|
|
41
|
+
this.provider = (0, import_puppuccino_core.createProviderInstance)(this.config);
|
|
42
|
+
this.tools = (0, import_puppuccino_core.createToolRegistry)();
|
|
43
|
+
this.sessionManager = (0, import_puppuccino_core.createSessionManager)();
|
|
44
|
+
this.hooks = (0, import_puppuccino_core.createHooksRunner)(this.config.hooks);
|
|
45
|
+
this.permissions = (0, import_puppuccino_core.createPermissionChecker)(this.config.permissions);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Send a query and get a response
|
|
49
|
+
*/
|
|
50
|
+
async query(message, options) {
|
|
51
|
+
const { sessionId, systemPrompt, maxTurns, onEvent } = options || {};
|
|
52
|
+
let session;
|
|
53
|
+
if (sessionId) {
|
|
54
|
+
const resumed = this.sessionManager.resume(sessionId);
|
|
55
|
+
if (!resumed) {
|
|
56
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
57
|
+
}
|
|
58
|
+
session = resumed;
|
|
59
|
+
} else if (this.sessionManager.current) {
|
|
60
|
+
session = this.sessionManager.current;
|
|
61
|
+
} else {
|
|
62
|
+
session = this.sessionManager.start({
|
|
63
|
+
projectPath: options?.cwd || process.cwd(),
|
|
64
|
+
model: this.config.model
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const userMessage = { role: "user", content: message };
|
|
68
|
+
this.sessionManager.addMessage(userMessage);
|
|
69
|
+
const events = [];
|
|
70
|
+
const texts = [];
|
|
71
|
+
const agentState = (0, import_puppuccino_core.createAgentState)(this.provider, this.tools, {
|
|
72
|
+
messages: session.messages,
|
|
73
|
+
hooks: this.hooks,
|
|
74
|
+
permissions: this.permissions,
|
|
75
|
+
systemPrompt: systemPrompt || this.config.agent?.systemPrompt || import_puppuccino_core.DEFAULT_SYSTEM_PROMPT,
|
|
76
|
+
maxTurns: maxTurns || this.config.agent?.maxTurns
|
|
77
|
+
});
|
|
78
|
+
for await (const event of (0, import_puppuccino_core.runAgentLoop)(agentState)) {
|
|
79
|
+
events.push(event);
|
|
80
|
+
if (event.type === "text") {
|
|
81
|
+
texts.push(event.content);
|
|
82
|
+
}
|
|
83
|
+
if (onEvent) {
|
|
84
|
+
onEvent(event);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
this.sessionManager.save();
|
|
88
|
+
return {
|
|
89
|
+
response: texts.join(""),
|
|
90
|
+
sessionId: session.id,
|
|
91
|
+
events,
|
|
92
|
+
messages: session.messages
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Stream a query response
|
|
97
|
+
*/
|
|
98
|
+
async *stream(message, options) {
|
|
99
|
+
const { sessionId, systemPrompt, maxTurns } = options || {};
|
|
100
|
+
let session;
|
|
101
|
+
if (sessionId) {
|
|
102
|
+
const resumed = this.sessionManager.resume(sessionId);
|
|
103
|
+
if (!resumed) {
|
|
104
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
105
|
+
}
|
|
106
|
+
session = resumed;
|
|
107
|
+
} else if (this.sessionManager.current) {
|
|
108
|
+
session = this.sessionManager.current;
|
|
109
|
+
} else {
|
|
110
|
+
session = this.sessionManager.start({
|
|
111
|
+
projectPath: options?.cwd || process.cwd(),
|
|
112
|
+
model: this.config.model
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const userMessage = { role: "user", content: message };
|
|
116
|
+
this.sessionManager.addMessage(userMessage);
|
|
117
|
+
const agentState = (0, import_puppuccino_core.createAgentState)(this.provider, this.tools, {
|
|
118
|
+
messages: session.messages,
|
|
119
|
+
hooks: this.hooks,
|
|
120
|
+
permissions: this.permissions,
|
|
121
|
+
systemPrompt: systemPrompt || this.config.agent?.systemPrompt || import_puppuccino_core.DEFAULT_SYSTEM_PROMPT,
|
|
122
|
+
maxTurns: maxTurns || this.config.agent?.maxTurns
|
|
123
|
+
});
|
|
124
|
+
for await (const event of (0, import_puppuccino_core.runAgentLoop)(agentState)) {
|
|
125
|
+
yield event;
|
|
126
|
+
}
|
|
127
|
+
this.sessionManager.save();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Start a new session
|
|
131
|
+
*/
|
|
132
|
+
startSession(options) {
|
|
133
|
+
return this.sessionManager.start(options);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Resume an existing session
|
|
137
|
+
*/
|
|
138
|
+
resumeSession(sessionId) {
|
|
139
|
+
return this.sessionManager.resume(sessionId);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Resume the most recent session
|
|
143
|
+
*/
|
|
144
|
+
resumeRecentSession() {
|
|
145
|
+
return this.sessionManager.resumeRecent();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get current session
|
|
149
|
+
*/
|
|
150
|
+
get currentSession() {
|
|
151
|
+
return this.sessionManager.current;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Clear current session
|
|
155
|
+
*/
|
|
156
|
+
clearSession() {
|
|
157
|
+
this.sessionManager.clear();
|
|
158
|
+
this.sessionManager.save();
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get configuration
|
|
162
|
+
*/
|
|
163
|
+
get currentConfig() {
|
|
164
|
+
return this.config;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Update configuration
|
|
168
|
+
*/
|
|
169
|
+
updateConfig(config) {
|
|
170
|
+
this.config = { ...this.config, ...config };
|
|
171
|
+
this.provider = (0, import_puppuccino_core.createProviderInstance)(this.config);
|
|
172
|
+
if (config.hooks) {
|
|
173
|
+
this.hooks = (0, import_puppuccino_core.createHooksRunner)(config.hooks);
|
|
174
|
+
}
|
|
175
|
+
if (config.permissions) {
|
|
176
|
+
this.permissions = (0, import_puppuccino_core.createPermissionChecker)(config.permissions);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
async function query(message, options) {
|
|
181
|
+
const client = new PuppuccinoClient(options?.config);
|
|
182
|
+
const result = await client.query(message, options);
|
|
183
|
+
return result.response;
|
|
184
|
+
}
|
|
185
|
+
function createClient(config) {
|
|
186
|
+
return new PuppuccinoClient(config);
|
|
187
|
+
}
|
|
188
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
+
0 && (module.exports = {
|
|
190
|
+
PuppuccinoClient,
|
|
191
|
+
createClient,
|
|
192
|
+
query
|
|
193
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
loadConfig,
|
|
4
|
+
createProviderInstance,
|
|
5
|
+
createToolRegistry,
|
|
6
|
+
createSessionManager,
|
|
7
|
+
createHooksRunner,
|
|
8
|
+
createPermissionChecker,
|
|
9
|
+
runAgentLoop,
|
|
10
|
+
createAgentState,
|
|
11
|
+
DEFAULT_SYSTEM_PROMPT
|
|
12
|
+
} from "@averagejoeslab/puppuccino-core";
|
|
13
|
+
var PuppuccinoClient = class {
|
|
14
|
+
config;
|
|
15
|
+
provider;
|
|
16
|
+
tools;
|
|
17
|
+
sessionManager;
|
|
18
|
+
hooks;
|
|
19
|
+
permissions;
|
|
20
|
+
constructor(config) {
|
|
21
|
+
this.config = loadConfig();
|
|
22
|
+
if (config) {
|
|
23
|
+
this.config = { ...this.config, ...config };
|
|
24
|
+
}
|
|
25
|
+
this.provider = createProviderInstance(this.config);
|
|
26
|
+
this.tools = createToolRegistry();
|
|
27
|
+
this.sessionManager = createSessionManager();
|
|
28
|
+
this.hooks = createHooksRunner(this.config.hooks);
|
|
29
|
+
this.permissions = createPermissionChecker(this.config.permissions);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Send a query and get a response
|
|
33
|
+
*/
|
|
34
|
+
async query(message, options) {
|
|
35
|
+
const { sessionId, systemPrompt, maxTurns, onEvent } = options || {};
|
|
36
|
+
let session;
|
|
37
|
+
if (sessionId) {
|
|
38
|
+
const resumed = this.sessionManager.resume(sessionId);
|
|
39
|
+
if (!resumed) {
|
|
40
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
41
|
+
}
|
|
42
|
+
session = resumed;
|
|
43
|
+
} else if (this.sessionManager.current) {
|
|
44
|
+
session = this.sessionManager.current;
|
|
45
|
+
} else {
|
|
46
|
+
session = this.sessionManager.start({
|
|
47
|
+
projectPath: options?.cwd || process.cwd(),
|
|
48
|
+
model: this.config.model
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const userMessage = { role: "user", content: message };
|
|
52
|
+
this.sessionManager.addMessage(userMessage);
|
|
53
|
+
const events = [];
|
|
54
|
+
const texts = [];
|
|
55
|
+
const agentState = createAgentState(this.provider, this.tools, {
|
|
56
|
+
messages: session.messages,
|
|
57
|
+
hooks: this.hooks,
|
|
58
|
+
permissions: this.permissions,
|
|
59
|
+
systemPrompt: systemPrompt || this.config.agent?.systemPrompt || DEFAULT_SYSTEM_PROMPT,
|
|
60
|
+
maxTurns: maxTurns || this.config.agent?.maxTurns
|
|
61
|
+
});
|
|
62
|
+
for await (const event of runAgentLoop(agentState)) {
|
|
63
|
+
events.push(event);
|
|
64
|
+
if (event.type === "text") {
|
|
65
|
+
texts.push(event.content);
|
|
66
|
+
}
|
|
67
|
+
if (onEvent) {
|
|
68
|
+
onEvent(event);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
this.sessionManager.save();
|
|
72
|
+
return {
|
|
73
|
+
response: texts.join(""),
|
|
74
|
+
sessionId: session.id,
|
|
75
|
+
events,
|
|
76
|
+
messages: session.messages
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Stream a query response
|
|
81
|
+
*/
|
|
82
|
+
async *stream(message, options) {
|
|
83
|
+
const { sessionId, systemPrompt, maxTurns } = options || {};
|
|
84
|
+
let session;
|
|
85
|
+
if (sessionId) {
|
|
86
|
+
const resumed = this.sessionManager.resume(sessionId);
|
|
87
|
+
if (!resumed) {
|
|
88
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
89
|
+
}
|
|
90
|
+
session = resumed;
|
|
91
|
+
} else if (this.sessionManager.current) {
|
|
92
|
+
session = this.sessionManager.current;
|
|
93
|
+
} else {
|
|
94
|
+
session = this.sessionManager.start({
|
|
95
|
+
projectPath: options?.cwd || process.cwd(),
|
|
96
|
+
model: this.config.model
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const userMessage = { role: "user", content: message };
|
|
100
|
+
this.sessionManager.addMessage(userMessage);
|
|
101
|
+
const agentState = createAgentState(this.provider, this.tools, {
|
|
102
|
+
messages: session.messages,
|
|
103
|
+
hooks: this.hooks,
|
|
104
|
+
permissions: this.permissions,
|
|
105
|
+
systemPrompt: systemPrompt || this.config.agent?.systemPrompt || DEFAULT_SYSTEM_PROMPT,
|
|
106
|
+
maxTurns: maxTurns || this.config.agent?.maxTurns
|
|
107
|
+
});
|
|
108
|
+
for await (const event of runAgentLoop(agentState)) {
|
|
109
|
+
yield event;
|
|
110
|
+
}
|
|
111
|
+
this.sessionManager.save();
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Start a new session
|
|
115
|
+
*/
|
|
116
|
+
startSession(options) {
|
|
117
|
+
return this.sessionManager.start(options);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Resume an existing session
|
|
121
|
+
*/
|
|
122
|
+
resumeSession(sessionId) {
|
|
123
|
+
return this.sessionManager.resume(sessionId);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Resume the most recent session
|
|
127
|
+
*/
|
|
128
|
+
resumeRecentSession() {
|
|
129
|
+
return this.sessionManager.resumeRecent();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get current session
|
|
133
|
+
*/
|
|
134
|
+
get currentSession() {
|
|
135
|
+
return this.sessionManager.current;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Clear current session
|
|
139
|
+
*/
|
|
140
|
+
clearSession() {
|
|
141
|
+
this.sessionManager.clear();
|
|
142
|
+
this.sessionManager.save();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get configuration
|
|
146
|
+
*/
|
|
147
|
+
get currentConfig() {
|
|
148
|
+
return this.config;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Update configuration
|
|
152
|
+
*/
|
|
153
|
+
updateConfig(config) {
|
|
154
|
+
this.config = { ...this.config, ...config };
|
|
155
|
+
this.provider = createProviderInstance(this.config);
|
|
156
|
+
if (config.hooks) {
|
|
157
|
+
this.hooks = createHooksRunner(config.hooks);
|
|
158
|
+
}
|
|
159
|
+
if (config.permissions) {
|
|
160
|
+
this.permissions = createPermissionChecker(config.permissions);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
async function query(message, options) {
|
|
165
|
+
const client = new PuppuccinoClient(options?.config);
|
|
166
|
+
const result = await client.query(message, options);
|
|
167
|
+
return result.response;
|
|
168
|
+
}
|
|
169
|
+
function createClient(config) {
|
|
170
|
+
return new PuppuccinoClient(config);
|
|
171
|
+
}
|
|
172
|
+
export {
|
|
173
|
+
PuppuccinoClient,
|
|
174
|
+
createClient,
|
|
175
|
+
query
|
|
176
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@averagejoeslab/puppuccino-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SDK for programmatic access to Puppuccino",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
18
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"clean": "rm -rf dist"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@averagejoeslab/puppuccino-core": "^0.1.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^20.0.0",
|
|
28
|
+
"tsup": "^8.0.0",
|
|
29
|
+
"typescript": "^5.4.0",
|
|
30
|
+
"vitest": "^2.0.0"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
]
|
|
35
|
+
}
|