@insta-dev01/insta-plugin-openclaw 1.0.0 → 1.0.2
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.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +171 -0
- package/dist/index.js.map +1 -0
- package/dist/src/channel/config.d.ts +9 -0
- package/dist/src/channel/config.d.ts.map +1 -0
- package/dist/src/channel/config.js +10 -0
- package/dist/src/channel/config.js.map +1 -0
- package/dist/src/channel/connection.d.ts +34 -0
- package/dist/src/channel/connection.d.ts.map +1 -0
- package/dist/src/channel/connection.js +281 -0
- package/dist/src/channel/connection.js.map +1 -0
- package/dist/src/channel/dispatcher.d.ts +43 -0
- package/dist/src/channel/dispatcher.d.ts.map +1 -0
- package/dist/src/channel/dispatcher.js +324 -0
- package/dist/src/channel/dispatcher.js.map +1 -0
- package/dist/src/channel/index.d.ts +5 -0
- package/dist/src/channel/index.d.ts.map +1 -0
- package/dist/src/channel/index.js +135 -0
- package/dist/src/channel/index.js.map +1 -0
- package/dist/src/channel/logger.d.ts +10 -0
- package/dist/src/channel/logger.d.ts.map +1 -0
- package/dist/src/channel/logger.js +30 -0
- package/dist/src/channel/logger.js.map +1 -0
- package/dist/src/channel/protocol.d.ts +15 -0
- package/dist/src/channel/protocol.d.ts.map +1 -0
- package/dist/src/channel/protocol.js +204 -0
- package/dist/src/channel/protocol.js.map +1 -0
- package/dist/src/channel/registrar.d.ts +21 -0
- package/dist/src/channel/registrar.d.ts.map +1 -0
- package/dist/src/channel/registrar.js +115 -0
- package/dist/src/channel/registrar.js.map +1 -0
- package/dist/src/channel/registration-store.d.ts +21 -0
- package/dist/src/channel/registration-store.d.ts.map +1 -0
- package/{src/channel/registration-store.ts → dist/src/channel/registration-store.js} +21 -46
- package/dist/src/channel/registration-store.js.map +1 -0
- package/dist/src/channel/types.d.ts +80 -0
- package/dist/src/channel/types.d.ts.map +1 -0
- package/dist/src/channel/types.js +3 -0
- package/dist/src/channel/types.js.map +1 -0
- package/dist/src/core/index.d.ts +5 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +3 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/register-identity.d.ts +58 -0
- package/dist/src/core/register-identity.d.ts.map +1 -0
- package/dist/src/core/register-identity.js +251 -0
- package/dist/src/core/register-identity.js.map +1 -0
- package/dist/src/core/task-api.d.ts +31 -0
- package/dist/src/core/task-api.d.ts.map +1 -0
- package/dist/src/core/task-api.js +116 -0
- package/dist/src/core/task-api.js.map +1 -0
- package/dist/src/core/urls.d.ts +33 -0
- package/dist/src/core/urls.d.ts.map +1 -0
- package/dist/src/core/urls.js +40 -0
- package/dist/src/core/urls.js.map +1 -0
- package/dist/src/tools/get-plugin-profile.d.ts +7 -0
- package/dist/src/tools/get-plugin-profile.d.ts.map +1 -0
- package/dist/src/tools/get-plugin-profile.js +132 -0
- package/dist/src/tools/get-plugin-profile.js.map +1 -0
- package/dist/src/tools/grab-task.d.ts +7 -0
- package/dist/src/tools/grab-task.d.ts.map +1 -0
- package/dist/src/tools/grab-task.js +100 -0
- package/dist/src/tools/grab-task.js.map +1 -0
- package/dist/src/tools/list-tasks.d.ts +7 -0
- package/dist/src/tools/list-tasks.d.ts.map +1 -0
- package/dist/src/tools/list-tasks.js +92 -0
- package/dist/src/tools/list-tasks.js.map +1 -0
- package/dist/src/tools/propose-registration.d.ts +14 -0
- package/dist/src/tools/propose-registration.d.ts.map +1 -0
- package/dist/src/tools/propose-registration.js +103 -0
- package/dist/src/tools/propose-registration.js.map +1 -0
- package/dist/src/tools/register-identity.d.ts +11 -0
- package/dist/src/tools/register-identity.d.ts.map +1 -0
- package/dist/src/tools/register-identity.js +101 -0
- package/dist/src/tools/register-identity.js.map +1 -0
- package/dist/src/tools/submit-deliverable.d.ts +17 -0
- package/dist/src/tools/submit-deliverable.d.ts.map +1 -0
- package/dist/src/tools/submit-deliverable.js +215 -0
- package/dist/src/tools/submit-deliverable.js.map +1 -0
- package/dist/src/tools/upload-artifact.d.ts +14 -0
- package/dist/src/tools/upload-artifact.d.ts.map +1 -0
- package/dist/src/tools/upload-artifact.js +166 -0
- package/dist/src/tools/upload-artifact.js.map +1 -0
- package/dist/src/utils/file-lock.d.ts +4 -0
- package/dist/src/utils/file-lock.d.ts.map +1 -0
- package/dist/src/utils/file-lock.js +43 -0
- package/dist/src/utils/file-lock.js.map +1 -0
- package/dist/src/utils/profile.d.ts +17 -0
- package/dist/src/utils/profile.d.ts.map +1 -0
- package/dist/src/utils/profile.js +26 -0
- package/dist/src/utils/profile.js.map +1 -0
- package/dist/src/utils/session.d.ts +3 -0
- package/dist/src/utils/session.d.ts.map +1 -0
- package/dist/src/utils/session.js +26 -0
- package/dist/src/utils/session.js.map +1 -0
- package/package.json +17 -5
- package/.env.example +0 -23
- package/channel/346/265/201/347/250/213/345/233/276.md +0 -477
- package/index.ts +0 -198
- package/src/channel/config.ts +0 -27
- package/src/channel/connection.ts +0 -341
- package/src/channel/dispatcher.ts +0 -374
- package/src/channel/index.ts +0 -173
- package/src/channel/logger.ts +0 -36
- package/src/channel/protocol.ts +0 -265
- package/src/channel/registrar.ts +0 -172
- package/src/channel/types.ts +0 -102
- package/src/core/index.ts +0 -13
- package/src/core/register-identity.ts +0 -326
- package/src/core/task-api.ts +0 -168
- package/src/core/urls.ts +0 -52
- package/src/prompt/job.md +0 -21
- package/src/tools/get-plugin-profile.ts +0 -152
- package/src/tools/grab-task.ts +0 -133
- package/src/tools/list-tasks.ts +0 -135
- package/src/tools/propose-registration.ts +0 -116
- package/src/tools/register-identity.ts +0 -121
- package/src/tools/submit-deliverable.ts +0 -268
- package/src/tools/upload-artifact.ts +0 -222
- package/src/utils/file-lock.ts +0 -43
- package/src/utils/profile.ts +0 -45
- package/src/utils/session.ts +0 -30
- package/tests/profile.test.ts +0 -70
- package/tests/session.test.ts +0 -53
- package/tsconfig.json +0 -49
- package/vitest.config.ts +0 -26
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { TEXT_CHUNK_SIZE } from "./config.js";
|
|
2
|
+
// ── Topics ────────────────────────────────────────────────────────────────────
|
|
3
|
+
export const TOPIC_BOT_MESSAGES = "/v1.0/im/bot/messages";
|
|
4
|
+
export const TOPIC_USER_MESSAGES = "/v1.0/im/user/messages";
|
|
5
|
+
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
6
|
+
function generateId(prefix) {
|
|
7
|
+
return `${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
8
|
+
}
|
|
9
|
+
function isoNow() {
|
|
10
|
+
return new Date().toISOString();
|
|
11
|
+
}
|
|
12
|
+
// ── Inbound Parsing ───────────────────────────────────────────────────────────
|
|
13
|
+
export function extractContentFromInput(input) {
|
|
14
|
+
const messageParts = [];
|
|
15
|
+
for (const item of input) {
|
|
16
|
+
if (!item || !Array.isArray(item.content) || item.content.length === 0) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const parts = [];
|
|
20
|
+
for (const part of item.content) {
|
|
21
|
+
if (!part || typeof part !== "object")
|
|
22
|
+
continue;
|
|
23
|
+
const p = part;
|
|
24
|
+
switch (p["type"]) {
|
|
25
|
+
case "input_text": {
|
|
26
|
+
const text = p["text"];
|
|
27
|
+
if (text && typeof text === "string" && text.trim()) {
|
|
28
|
+
parts.push(`> ${text}`);
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case "input_file": {
|
|
33
|
+
const filename = typeof p["filename"] === "string" ? p["filename"] : "file";
|
|
34
|
+
const url = (p["file_url"] || p["url"]);
|
|
35
|
+
if (url) {
|
|
36
|
+
parts.push(`[${filename}](${url})`);
|
|
37
|
+
}
|
|
38
|
+
else if (typeof p["file_id"] === "string") {
|
|
39
|
+
parts.push(`[${filename}](file:${p["file_id"]})`);
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case "input_image": {
|
|
44
|
+
const filename = typeof p["filename"] === "string" ? p["filename"] : "image";
|
|
45
|
+
const url = (p["image_url"] || p["url"]);
|
|
46
|
+
if (url) {
|
|
47
|
+
parts.push(``);
|
|
48
|
+
}
|
|
49
|
+
else if (typeof p["file_id"] === "string") {
|
|
50
|
+
parts.push(``);
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (parts.length > 0) {
|
|
57
|
+
messageParts.push(parts.join("\n\n"));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return messageParts.join("\n\n---\n\n");
|
|
61
|
+
}
|
|
62
|
+
export function parseRequest(rawMessage) {
|
|
63
|
+
let request;
|
|
64
|
+
try {
|
|
65
|
+
request = JSON.parse(rawMessage);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
throw new Error(`Failed to parse request JSON: ${err.message}`);
|
|
69
|
+
}
|
|
70
|
+
const input = request["input"];
|
|
71
|
+
if (!Array.isArray(input) || input.length === 0) {
|
|
72
|
+
throw new Error("Invalid request: missing or empty input array");
|
|
73
|
+
}
|
|
74
|
+
const content = extractContentFromInput(input);
|
|
75
|
+
if (!content.trim()) {
|
|
76
|
+
throw new Error("Invalid request: no extractable content in input");
|
|
77
|
+
}
|
|
78
|
+
const meta = request["metadata"];
|
|
79
|
+
const sessionId = meta?.["session_id"] && typeof meta["session_id"] === "string"
|
|
80
|
+
? meta["session_id"]
|
|
81
|
+
: generateId("msg");
|
|
82
|
+
const messageId = meta?.["message_id"] && typeof meta["message_id"] === "string"
|
|
83
|
+
? meta["message_id"]
|
|
84
|
+
: generateId("msg");
|
|
85
|
+
return {
|
|
86
|
+
content,
|
|
87
|
+
messageId,
|
|
88
|
+
sessionId,
|
|
89
|
+
topic: TOPIC_USER_MESSAGES,
|
|
90
|
+
model: typeof request["model"] === "string" ? request["model"] : undefined,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// ── Envelope Parsing ──────────────────────────────────────────────────────────
|
|
94
|
+
export function parseEnvelope(rawMessage) {
|
|
95
|
+
let envelope;
|
|
96
|
+
try {
|
|
97
|
+
envelope = JSON.parse(rawMessage);
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
throw new Error(`Failed to parse envelope: ${err.message}`);
|
|
101
|
+
}
|
|
102
|
+
if (envelope["type"] !== "MESSAGE") {
|
|
103
|
+
throw new Error(`Invalid envelope: expected type "MESSAGE", got "${envelope["type"]}"`);
|
|
104
|
+
}
|
|
105
|
+
const data = envelope["data"];
|
|
106
|
+
if (typeof data !== "string") {
|
|
107
|
+
throw new Error("Invalid envelope: data must be a string");
|
|
108
|
+
}
|
|
109
|
+
const event = JSON.parse(data);
|
|
110
|
+
if (!event.type || !event.response_id) {
|
|
111
|
+
throw new Error("Invalid event: missing type or response_id");
|
|
112
|
+
}
|
|
113
|
+
return event;
|
|
114
|
+
}
|
|
115
|
+
// ── Serialization ─────────────────────────────────────────────────────────────
|
|
116
|
+
export function createEnvelope(event) {
|
|
117
|
+
return JSON.stringify(event);
|
|
118
|
+
}
|
|
119
|
+
// ── Event Factories ───────────────────────────────────────────────────────────
|
|
120
|
+
export function createInProgressEvent(responseId, sessionId) {
|
|
121
|
+
const event = {
|
|
122
|
+
type: "response.in_progress",
|
|
123
|
+
response_id: responseId,
|
|
124
|
+
status: "in_progress",
|
|
125
|
+
timestamp: isoNow(),
|
|
126
|
+
};
|
|
127
|
+
if (sessionId)
|
|
128
|
+
event.metadata = { session_id: sessionId };
|
|
129
|
+
return event;
|
|
130
|
+
}
|
|
131
|
+
export function createOutputItemAddedEvent(responseId, itemId, index = 0) {
|
|
132
|
+
return {
|
|
133
|
+
type: "response.output_item.added",
|
|
134
|
+
response_id: responseId,
|
|
135
|
+
item: {
|
|
136
|
+
id: itemId,
|
|
137
|
+
type: "message",
|
|
138
|
+
status: "in_progress",
|
|
139
|
+
role: "assistant",
|
|
140
|
+
content: [{ type: "output_text", status: "in_progress", text: "" }],
|
|
141
|
+
},
|
|
142
|
+
index,
|
|
143
|
+
timestamp: isoNow(),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
export function createOutputTextDeltaEvent(responseId, itemId, contentIndex, text) {
|
|
147
|
+
return {
|
|
148
|
+
type: "response.output_text.delta",
|
|
149
|
+
response_id: responseId,
|
|
150
|
+
item_id: itemId,
|
|
151
|
+
content_index: contentIndex,
|
|
152
|
+
delta: { text },
|
|
153
|
+
timestamp: isoNow(),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
export function createContentPartDoneEvent(responseId, itemId, contentIndex) {
|
|
157
|
+
return {
|
|
158
|
+
type: "response.content_part.done",
|
|
159
|
+
response_id: responseId,
|
|
160
|
+
item_id: itemId,
|
|
161
|
+
content_index: contentIndex,
|
|
162
|
+
status: "completed",
|
|
163
|
+
timestamp: isoNow(),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export function createCompletedEvent(responseId, sessionId) {
|
|
167
|
+
const event = {
|
|
168
|
+
type: "response.completed",
|
|
169
|
+
response_id: responseId,
|
|
170
|
+
status: "completed",
|
|
171
|
+
timestamp: isoNow(),
|
|
172
|
+
};
|
|
173
|
+
if (sessionId)
|
|
174
|
+
event.metadata = { session_id: sessionId };
|
|
175
|
+
return event;
|
|
176
|
+
}
|
|
177
|
+
export function createFailedEvent(responseId, code, message, details = null, sessionId) {
|
|
178
|
+
const event = {
|
|
179
|
+
type: "response.failed",
|
|
180
|
+
response_id: responseId,
|
|
181
|
+
status: "failed",
|
|
182
|
+
error: { code, message, details },
|
|
183
|
+
timestamp: isoNow(),
|
|
184
|
+
};
|
|
185
|
+
if (sessionId)
|
|
186
|
+
event.metadata = { session_id: sessionId };
|
|
187
|
+
return event;
|
|
188
|
+
}
|
|
189
|
+
// ── Text → Event Sequence ─────────────────────────────────────────────────────
|
|
190
|
+
export function textToEventSequence(text, responseId) {
|
|
191
|
+
const respId = responseId ?? generateId("resp");
|
|
192
|
+
const itemId = generateId("item");
|
|
193
|
+
const events = [
|
|
194
|
+
createInProgressEvent(respId),
|
|
195
|
+
createOutputItemAddedEvent(respId, itemId),
|
|
196
|
+
];
|
|
197
|
+
for (let i = 0; i < text.length; i += TEXT_CHUNK_SIZE) {
|
|
198
|
+
events.push(createOutputTextDeltaEvent(respId, itemId, 0, text.substring(i, i + TEXT_CHUNK_SIZE)));
|
|
199
|
+
}
|
|
200
|
+
events.push(createContentPartDoneEvent(respId, itemId, 0));
|
|
201
|
+
events.push(createCompletedEvent(respId));
|
|
202
|
+
return events;
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/channel/protocol.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,iFAAiF;AAEjF,MAAM,CAAC,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAC1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,wBAAwB,CAAC;AAE5D,iFAAiF;AAEjF,SAAS,UAAU,CAAC,MAAc;IAChC,OAAO,GAAG,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;AAClF,CAAC;AAED,SAAS,MAAM;IACb,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAED,iFAAiF;AAEjF,MAAM,UAAU,uBAAuB,CAAC,KAAgB;IACtD,MAAM,YAAY,GAAa,EAAE,CAAC;IAElC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAE,IAA8B,CAAC,OAAO,CAAC,IAAK,IAA+B,CAAC,OAAO,CAA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E,OAAO,EAAE,OAAO,EAAE;QACjC,SAAS,EAAE,MAAM,EAAE;KACpB,CAAC;IACF,IAAI,SAAS;QAAE,KAAK,CAAC,QAAQ,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;IAC1D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,iFAAiF;AAEjF,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,UAAmB;IACnE,MAAM,MAAM,GAAG,UAAU,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IAElC,MAAM,MAAM,GAAyB;QACnC,qBAAqB,CAAC,MAAM,CAAC;QAC7B,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC;KAC3C,CAAC;IAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,eAAe,EAAE,CAAC;QACtD,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;IACrG,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3D,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;IAE1C,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { VALID_SCENE_TAG_IDS } from "../core/register-identity.js";
|
|
2
|
+
import type { DebugLogger } from "./logger.js";
|
|
3
|
+
export type RegistrarStatus = "triggered" | "unavailable" | "error";
|
|
4
|
+
export interface RegistrarResult {
|
|
5
|
+
status: RegistrarStatus;
|
|
6
|
+
error?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Fire-and-forget: uses `channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher`
|
|
10
|
+
* to launch a synthetic AI conversation that auto-calls `insta_register_identity`.
|
|
11
|
+
*
|
|
12
|
+
* Unlike `subagent.run`, `dispatchReplyWithBufferedBlockDispatcher` is available
|
|
13
|
+
* at any point during the channel lifecycle, including inside `startAccount`.
|
|
14
|
+
*
|
|
15
|
+
* The AI response text is discarded — only the tool call side-effect matters
|
|
16
|
+
* (writing the profile file). The polling loop in `startAccount` detects the
|
|
17
|
+
* resulting profile and establishes the WebSocket connection.
|
|
18
|
+
*/
|
|
19
|
+
export declare function triggerRegistrationAgent(channelRuntime: unknown, cfg: unknown, logger: DebugLogger, accountId?: string): Promise<RegistrarResult>;
|
|
20
|
+
export { VALID_SCENE_TAG_IDS };
|
|
21
|
+
//# sourceMappingURL=registrar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../../src/channel/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAc,MAAM,8BAA8B,CAAC;AAE/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAgD/C,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,aAAa,GAAG,OAAO,CAAC;AAEpE,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAuBD;;;;;;;;;;GAUG;AACH,wBAAsB,wBAAwB,CAC5C,cAAc,EAAE,OAAO,EACvB,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,WAAW,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,CAAC,CA2E1B;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { VALID_SCENE_TAG_IDS, SCENE_TAGS } from "../core/register-identity.js";
|
|
2
|
+
import { setAgentRunning, getPendingRegistration } from "./registration-store.js";
|
|
3
|
+
// ── Registration prompts ──────────────────────────────────────────────────────
|
|
4
|
+
const SCENE_TAG_SUMMARY = Object.entries(SCENE_TAGS)
|
|
5
|
+
.map(([, group]) => Object.entries(group.children)
|
|
6
|
+
.map(([id, label]) => ` ${id}: ${label}`)
|
|
7
|
+
.join("\n"))
|
|
8
|
+
.join("\n");
|
|
9
|
+
/**
|
|
10
|
+
* System prompt instructs the AI to decide sensible defaults autonomously and
|
|
11
|
+
* call `insta_propose_registration` to store them for user review.
|
|
12
|
+
*
|
|
13
|
+
* The AI must NOT call `insta_register_identity` directly — the actual
|
|
14
|
+
* registration happens only after the user confirms via the gateway UI.
|
|
15
|
+
*/
|
|
16
|
+
const REGISTRATION_SYSTEM_PROMPT = `
|
|
17
|
+
你是 InstaClaw 频道配置向导。InstaClaw 是一个 AI 代理接单平台。
|
|
18
|
+
|
|
19
|
+
本次调用是插件在首次启动时自动触发的。你的任务是根据当前 Agent 的上下文,推断合理的注册默认参数,
|
|
20
|
+
然后调用 insta_propose_registration 将这些参数暂存,由用户在控制面板中审阅并最终确认。
|
|
21
|
+
|
|
22
|
+
【重要】不要调用 insta_register_identity,不要直接完成注册。只调用 insta_propose_registration。
|
|
23
|
+
|
|
24
|
+
参数推断规则:
|
|
25
|
+
- name:根据 Agent 名称或用途取一个简洁有辨识度的名称
|
|
26
|
+
- avatar:使用占位头像,例如 https://api.dicebear.com/7.x/bottts/svg?seed=instaclaw
|
|
27
|
+
- description:简短描述当前 Agent 的主要能力(1-2 句话)
|
|
28
|
+
- hourly_rate:默认设为 100(单位:元)
|
|
29
|
+
- scene_tags:从以下合法 ID 中选 1-3 个最符合当前 Agent 定位的:
|
|
30
|
+
${SCENE_TAG_SUMMARY}
|
|
31
|
+
- custom_tags:可留空数组 []
|
|
32
|
+
- instance_type:固定填 0(本地实例)
|
|
33
|
+
|
|
34
|
+
行动要求:
|
|
35
|
+
1. 根据上述规则自主决定每个参数的值
|
|
36
|
+
2. 调用 insta_propose_registration 提交提案(参数将暂存,等待用户确认)
|
|
37
|
+
3. 不要输出多余的解释,直接执行工具调用
|
|
38
|
+
`.trim();
|
|
39
|
+
const REGISTRATION_INITIAL_PROMPT = "InstaClaw 频道首次启动,尚未完成注册。请根据当前 Agent 上下文推断合理的默认注册参数,调用 insta_propose_registration 提交提案,用户将在控制面板中确认后完成注册。";
|
|
40
|
+
// ── Trigger ───────────────────────────────────────────────────────────────────
|
|
41
|
+
/**
|
|
42
|
+
* Fire-and-forget: uses `channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher`
|
|
43
|
+
* to launch a synthetic AI conversation that auto-calls `insta_register_identity`.
|
|
44
|
+
*
|
|
45
|
+
* Unlike `subagent.run`, `dispatchReplyWithBufferedBlockDispatcher` is available
|
|
46
|
+
* at any point during the channel lifecycle, including inside `startAccount`.
|
|
47
|
+
*
|
|
48
|
+
* The AI response text is discarded — only the tool call side-effect matters
|
|
49
|
+
* (writing the profile file). The polling loop in `startAccount` detects the
|
|
50
|
+
* resulting profile and establishes the WebSocket connection.
|
|
51
|
+
*/
|
|
52
|
+
export async function triggerRegistrationAgent(channelRuntime, cfg, logger, accountId) {
|
|
53
|
+
const runtime = channelRuntime;
|
|
54
|
+
if (!runtime?.reply?.dispatchReplyWithBufferedBlockDispatcher) {
|
|
55
|
+
logger.warn("channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher not available. " +
|
|
56
|
+
"Register manually by calling the insta_register_identity tool.");
|
|
57
|
+
return { status: "unavailable" };
|
|
58
|
+
}
|
|
59
|
+
const msgCtx = {
|
|
60
|
+
Body: REGISTRATION_INITIAL_PROMPT,
|
|
61
|
+
AccountId: accountId ?? "default",
|
|
62
|
+
SessionKey: `instaclaw:${accountId ?? "default"}:registration`,
|
|
63
|
+
SystemPrompt: REGISTRATION_SYSTEM_PROMPT,
|
|
64
|
+
};
|
|
65
|
+
try {
|
|
66
|
+
// Mark in-flight BEFORE the async dispatch so the polling loop
|
|
67
|
+
// immediately sees "running" on the very next tick.
|
|
68
|
+
setAgentRunning(true);
|
|
69
|
+
// Fire-and-forget: errors from the AI run are caught below and logged,
|
|
70
|
+
// but do not block the polling loop.
|
|
71
|
+
void runtime.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
72
|
+
ctx: msgCtx,
|
|
73
|
+
cfg,
|
|
74
|
+
replyOptions: {
|
|
75
|
+
onPartialReply: (_payload) => {
|
|
76
|
+
// Intentionally discard streaming text — we only care about tool calls.
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
dispatcherOptions: {
|
|
80
|
+
deliver: async (_payload) => {
|
|
81
|
+
// Bug 2 fix: always clear the running flag so startAccount can
|
|
82
|
+
// re-trigger if the AI completed without calling insta_propose_registration.
|
|
83
|
+
setAgentRunning(false);
|
|
84
|
+
if (getPendingRegistration()) {
|
|
85
|
+
logger.info("Registration agent completed — proposal stored, waiting for user confirmation");
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
logger.warn("Registration agent completed but no proposal was created. " +
|
|
89
|
+
"startAccount will re-trigger on the next poll cycle.");
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
onError: (err) => {
|
|
93
|
+
// Clear the running flag so the polling loop can recover.
|
|
94
|
+
setAgentRunning(false);
|
|
95
|
+
logger.error("Registration agent dispatch error", err instanceof Error ? err : new Error(String(err)));
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
}).catch((err) => {
|
|
99
|
+
// Hard rejection (e.g. runtime unavailable mid-flight): also clear flag.
|
|
100
|
+
setAgentRunning(false);
|
|
101
|
+
logger.error("Registration agent dispatch rejected", err instanceof Error ? err : new Error(String(err)));
|
|
102
|
+
});
|
|
103
|
+
logger.info("Registration agent dispatch triggered via dispatchReplyWithBufferedBlockDispatcher");
|
|
104
|
+
return { status: "triggered" };
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
// Synchronous throw before dispatch could start — clear flag.
|
|
108
|
+
setAgentRunning(false);
|
|
109
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
110
|
+
logger.error("Failed to trigger registration agent dispatch", err instanceof Error ? err : undefined);
|
|
111
|
+
return { status: "error", error: message };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export { VALID_SCENE_TAG_IDS };
|
|
115
|
+
//# sourceMappingURL=registrar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registrar.js","sourceRoot":"","sources":["../../../src/channel/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGlF,iFAAiF;AAEjF,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;KACjD,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CACjB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC;KAC3B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,EAAE,CAAC;KACzC,IAAI,CAAC,IAAI,CAAC,CACd;KACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAEd;;;;;;GAMG;AACH,MAAM,0BAA0B,GAAG;;;;;;;;;;;;;;EAcjC,iBAAiB;;;;;;;;CAQlB,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,2BAA2B,GAC/B,yGAAyG,CAAC;AA8B5G,iFAAiF;AAEjF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,cAAuB,EACvB,GAAY,EACZ,MAAmB,EACnB,SAAkB;IAElB,MAAM,OAAO,GAAG,cAAqD,CAAC;IAEtE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,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;gBACJ,CAAC;aACF;SACF,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;YACxB,yEAAyE;YACzE,eAAe,CAAC,KAAK,CAAC,CAAC;YACvB,MAAM,CAAC,KAAK,CACV,sCAAsC,EACtC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CACpD,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,oFAAoF,CAAC,CAAC;QAClG,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IACjC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,8DAA8D;QAC9D,eAAe,CAAC,KAAK,CAAC,CAAC;QACvB,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,MAAM,CAAC,KAAK,CAAC,+CAA+C,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACtG,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAC7C,CAAC;AACH,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RegisterIdentityParams } from "../core/register-identity.js";
|
|
2
|
+
export interface PendingRegistration {
|
|
3
|
+
status: "pending_confirmation";
|
|
4
|
+
params: RegisterIdentityParams;
|
|
5
|
+
createdAt: number;
|
|
6
|
+
}
|
|
7
|
+
/** Store a set of AI-proposed registration params, waiting for user confirmation. */
|
|
8
|
+
export declare function setPendingRegistration(params: RegisterIdentityParams): void;
|
|
9
|
+
/** Return the currently pending registration, or null if none. */
|
|
10
|
+
export declare function getPendingRegistration(): PendingRegistration | null;
|
|
11
|
+
/** Remove the pending registration (call after successful submit or cancel). */
|
|
12
|
+
export declare function clearPendingRegistration(): void;
|
|
13
|
+
/** Called by `startAccount` as soon as baseDir is resolved. */
|
|
14
|
+
export declare function setBaseDir(dir: string): void;
|
|
15
|
+
/** Returns the most recently cached baseDir, falling back to process.cwd(). */
|
|
16
|
+
export declare function getBaseDir(): string;
|
|
17
|
+
/** Mark the registration agent as in-flight. */
|
|
18
|
+
export declare function setAgentRunning(running: boolean): void;
|
|
19
|
+
/** True while a dispatch is in-flight; false once deliver/catch fires. */
|
|
20
|
+
export declare function isAgentRunning(): boolean;
|
|
21
|
+
//# sourceMappingURL=registration-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration-store.d.ts","sourceRoot":"","sources":["../../../src/channel/registration-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAS3E,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,sBAAsB,CAAC;IAC/B,MAAM,EAAE,sBAAsB,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;CACnB;AAID,qFAAqF;AACrF,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI,CAM3E;AAED,kEAAkE;AAClE,wBAAgB,sBAAsB,IAAI,mBAAmB,GAAG,IAAI,CAEnE;AAED,gFAAgF;AAChF,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C;AAUD,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE5C;AAED,+EAA+E;AAC/E,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAgBD,gDAAgD;AAChD,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAEtD;AAED,0EAA0E;AAC1E,wBAAgB,cAAc,IAAI,OAAO,CAExC"}
|
|
@@ -1,57 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// ── Pending registration state ────────────────────────────────────────────────
|
|
4
|
-
//
|
|
5
|
-
// When the registration agent runs it calls `insta_propose_registration` which
|
|
6
|
-
// writes here. The session extension projects this data to the Gateway client
|
|
7
|
-
// so the confirmation control UI can display it. Once the user confirms via the
|
|
8
|
-
// `instaclaw.registration.submit` gateway method the pending record is cleared.
|
|
9
|
-
|
|
10
|
-
export interface PendingRegistration {
|
|
11
|
-
status: "pending_confirmation";
|
|
12
|
-
params: RegisterIdentityParams;
|
|
13
|
-
createdAt: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let _pending: PendingRegistration | null = null;
|
|
17
|
-
|
|
1
|
+
let _pending = null;
|
|
18
2
|
/** Store a set of AI-proposed registration params, waiting for user confirmation. */
|
|
19
|
-
export function setPendingRegistration(params
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
export function setPendingRegistration(params) {
|
|
4
|
+
_pending = {
|
|
5
|
+
status: "pending_confirmation",
|
|
6
|
+
params,
|
|
7
|
+
createdAt: Date.now(),
|
|
8
|
+
};
|
|
25
9
|
}
|
|
26
|
-
|
|
27
10
|
/** Return the currently pending registration, or null if none. */
|
|
28
|
-
export function getPendingRegistration()
|
|
29
|
-
|
|
11
|
+
export function getPendingRegistration() {
|
|
12
|
+
return _pending;
|
|
30
13
|
}
|
|
31
|
-
|
|
32
14
|
/** Remove the pending registration (call after successful submit or cancel). */
|
|
33
|
-
export function clearPendingRegistration()
|
|
34
|
-
|
|
15
|
+
export function clearPendingRegistration() {
|
|
16
|
+
_pending = null;
|
|
35
17
|
}
|
|
36
|
-
|
|
37
18
|
// ── Bug 1 fix: baseDir cache ──────────────────────────────────────────────────
|
|
38
19
|
//
|
|
39
20
|
// `startAccount` resolves baseDir from `cfg` (agentDir / workspaceDir / cwd).
|
|
40
21
|
// The gateway method runs outside that context, so it reads the cached value
|
|
41
22
|
// instead of falling back to process.cwd() which may differ.
|
|
42
|
-
|
|
43
|
-
let _baseDir: string | null = null;
|
|
44
|
-
|
|
23
|
+
let _baseDir = null;
|
|
45
24
|
/** Called by `startAccount` as soon as baseDir is resolved. */
|
|
46
|
-
export function setBaseDir(dir
|
|
47
|
-
|
|
25
|
+
export function setBaseDir(dir) {
|
|
26
|
+
_baseDir = dir;
|
|
48
27
|
}
|
|
49
|
-
|
|
50
28
|
/** Returns the most recently cached baseDir, falling back to process.cwd(). */
|
|
51
|
-
export function getBaseDir()
|
|
52
|
-
|
|
29
|
+
export function getBaseDir() {
|
|
30
|
+
return _baseDir ?? process.cwd();
|
|
53
31
|
}
|
|
54
|
-
|
|
55
32
|
// ── Bug 2 fix: agent-running flag ─────────────────────────────────────────────
|
|
56
33
|
//
|
|
57
34
|
// Tracks whether a registration agent dispatch is currently in-flight.
|
|
@@ -63,15 +40,13 @@ export function getBaseDir(): string {
|
|
|
63
40
|
// - agent running → skip (already in flight)
|
|
64
41
|
// - pending exists → skip (proposal already created, waiting for user)
|
|
65
42
|
// - neither → trigger (covers both first run and recovery after failure)
|
|
66
|
-
|
|
67
43
|
let _agentRunning = false;
|
|
68
|
-
|
|
69
44
|
/** Mark the registration agent as in-flight. */
|
|
70
|
-
export function setAgentRunning(running
|
|
71
|
-
|
|
45
|
+
export function setAgentRunning(running) {
|
|
46
|
+
_agentRunning = running;
|
|
72
47
|
}
|
|
73
|
-
|
|
74
48
|
/** True while a dispatch is in-flight; false once deliver/catch fires. */
|
|
75
|
-
export function isAgentRunning()
|
|
76
|
-
|
|
49
|
+
export function isAgentRunning() {
|
|
50
|
+
return _agentRunning;
|
|
77
51
|
}
|
|
52
|
+
//# sourceMappingURL=registration-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration-store.js","sourceRoot":"","sources":["../../../src/channel/registration-store.ts"],"names":[],"mappings":"AAeA,IAAI,QAAQ,GAA+B,IAAI,CAAC;AAEhD,qFAAqF;AACrF,MAAM,UAAU,sBAAsB,CAAC,MAA8B;IACnE,QAAQ,GAAG;QACT,MAAM,EAAE,sBAAsB;QAC9B,MAAM;QACN,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACtB,CAAC;AACJ,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,sBAAsB;IACpC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,wBAAwB;IACtC,QAAQ,GAAG,IAAI,CAAC;AAClB,CAAC;AAED,iFAAiF;AACjF,EAAE;AACF,8EAA8E;AAC9E,6EAA6E;AAC7E,6DAA6D;AAE7D,IAAI,QAAQ,GAAkB,IAAI,CAAC;AAEnC,+DAA+D;AAC/D,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,QAAQ,GAAG,GAAG,CAAC;AACjB,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,UAAU;IACxB,OAAO,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;AACnC,CAAC;AAED,iFAAiF;AACjF,EAAE;AACF,uEAAuE;AACvE,6EAA6E;AAC7E,qEAAqE;AACrE,EAAE;AACF,8EAA8E;AAC9E,mCAAmC;AACnC,gDAAgD;AAChD,yEAAyE;AACzE,kFAAkF;AAElF,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B,gDAAgD;AAChD,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,aAAa,GAAG,OAAO,CAAC;AAC1B,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,cAAc;IAC5B,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export type ConnectionState = "connecting" | "connected" | "disconnected" | "reconnecting";
|
|
2
|
+
export interface ConnectionConfig {
|
|
3
|
+
wsUrl: string;
|
|
4
|
+
clientId: string;
|
|
5
|
+
clientSecret: string;
|
|
6
|
+
heartbeatInterval: number;
|
|
7
|
+
reconnectMaxAttempts?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface WebSocketEnvelope {
|
|
10
|
+
type: "MESSAGE";
|
|
11
|
+
headers: {
|
|
12
|
+
messageId: string;
|
|
13
|
+
topic: string;
|
|
14
|
+
[key: string]: string;
|
|
15
|
+
};
|
|
16
|
+
data: string;
|
|
17
|
+
}
|
|
18
|
+
export interface BaseEvent {
|
|
19
|
+
type: string;
|
|
20
|
+
response_id: string;
|
|
21
|
+
timestamp: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ResponseInProgressEvent extends BaseEvent {
|
|
24
|
+
type: "response.in_progress";
|
|
25
|
+
status: "in_progress";
|
|
26
|
+
}
|
|
27
|
+
export interface OutputItemAddedEvent extends BaseEvent {
|
|
28
|
+
type: "response.output_item.added";
|
|
29
|
+
item: Item;
|
|
30
|
+
index: number;
|
|
31
|
+
}
|
|
32
|
+
export interface OutputTextDeltaEvent extends BaseEvent {
|
|
33
|
+
type: "response.output_text.delta";
|
|
34
|
+
item_id: string;
|
|
35
|
+
content_index: number;
|
|
36
|
+
delta: {
|
|
37
|
+
text: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface ContentPartDoneEvent extends BaseEvent {
|
|
41
|
+
type: "response.content_part.done";
|
|
42
|
+
item_id: string;
|
|
43
|
+
content_index: number;
|
|
44
|
+
status: "completed";
|
|
45
|
+
}
|
|
46
|
+
export interface ResponseCompletedEvent extends BaseEvent {
|
|
47
|
+
type: "response.completed";
|
|
48
|
+
status: "completed";
|
|
49
|
+
}
|
|
50
|
+
export interface ResponseFailedEvent extends BaseEvent {
|
|
51
|
+
type: "response.failed";
|
|
52
|
+
status: "failed";
|
|
53
|
+
error: {
|
|
54
|
+
code: string;
|
|
55
|
+
message: string;
|
|
56
|
+
details: unknown;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export type OpenResponsesEvent = ResponseInProgressEvent | OutputItemAddedEvent | OutputTextDeltaEvent | ContentPartDoneEvent | ResponseCompletedEvent | ResponseFailedEvent;
|
|
60
|
+
export interface ContentPart {
|
|
61
|
+
type: "output_text";
|
|
62
|
+
status: "in_progress" | "completed";
|
|
63
|
+
text: string;
|
|
64
|
+
}
|
|
65
|
+
export interface Item {
|
|
66
|
+
id: string;
|
|
67
|
+
type: "message" | "function_call" | "function_call_output" | "reasoning";
|
|
68
|
+
status: "in_progress" | "completed" | "incomplete" | "failed";
|
|
69
|
+
role?: "assistant" | "user";
|
|
70
|
+
content: ContentPart[];
|
|
71
|
+
}
|
|
72
|
+
export interface RequestContent {
|
|
73
|
+
content: string;
|
|
74
|
+
messageId: string;
|
|
75
|
+
topic: string;
|
|
76
|
+
sessionId: string;
|
|
77
|
+
model?: string;
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/channel/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,WAAW,GAAG,cAAc,GAAG,cAAc,CAAC;AAE3F,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAID,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE;QACP,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,CAAC;IACF,IAAI,EAAE,MAAM,CAAC;CACd;AAID,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WA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CAAC;IACX,IAAI,EAAE,SAAS,GAAG,eAAe,GAAG,sBAAsB,GAAG,WAAW,CAAC;IACzE,MAAM,EAAE,aAAa,GAAG,WAAW,GAAG,YAAY,GAAG,QAAQ,CAAC;IAC9D,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IAC5B,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB;AAID,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/channel/types.ts"],"names":[],"mappings":"AAAA,gFAAgF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { registerIdentity, SCENE_TAGS, VALID_SCENE_TAG_IDS, } from "./register-identity.js";
|
|
2
|
+
export type { RegisterIdentityParams, RegisterIdentityResponse, RegisterIdentityResult, } from "./register-identity.js";
|
|
3
|
+
export { getInstaUrl } from "./urls.js";
|
|
4
|
+
export type { UrlKey } from "./urls.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,YAAY,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAOhC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|