@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.
Files changed (127) hide show
  1. package/dist/index.d.ts +9 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +171 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/src/channel/config.d.ts +9 -0
  6. package/dist/src/channel/config.d.ts.map +1 -0
  7. package/dist/src/channel/config.js +10 -0
  8. package/dist/src/channel/config.js.map +1 -0
  9. package/dist/src/channel/connection.d.ts +34 -0
  10. package/dist/src/channel/connection.d.ts.map +1 -0
  11. package/dist/src/channel/connection.js +281 -0
  12. package/dist/src/channel/connection.js.map +1 -0
  13. package/dist/src/channel/dispatcher.d.ts +43 -0
  14. package/dist/src/channel/dispatcher.d.ts.map +1 -0
  15. package/dist/src/channel/dispatcher.js +324 -0
  16. package/dist/src/channel/dispatcher.js.map +1 -0
  17. package/dist/src/channel/index.d.ts +5 -0
  18. package/dist/src/channel/index.d.ts.map +1 -0
  19. package/dist/src/channel/index.js +135 -0
  20. package/dist/src/channel/index.js.map +1 -0
  21. package/dist/src/channel/logger.d.ts +10 -0
  22. package/dist/src/channel/logger.d.ts.map +1 -0
  23. package/dist/src/channel/logger.js +30 -0
  24. package/dist/src/channel/logger.js.map +1 -0
  25. package/dist/src/channel/protocol.d.ts +15 -0
  26. package/dist/src/channel/protocol.d.ts.map +1 -0
  27. package/dist/src/channel/protocol.js +204 -0
  28. package/dist/src/channel/protocol.js.map +1 -0
  29. package/dist/src/channel/registrar.d.ts +21 -0
  30. package/dist/src/channel/registrar.d.ts.map +1 -0
  31. package/dist/src/channel/registrar.js +115 -0
  32. package/dist/src/channel/registrar.js.map +1 -0
  33. package/dist/src/channel/registration-store.d.ts +21 -0
  34. package/dist/src/channel/registration-store.d.ts.map +1 -0
  35. package/{src/channel/registration-store.ts → dist/src/channel/registration-store.js} +21 -46
  36. package/dist/src/channel/registration-store.js.map +1 -0
  37. package/dist/src/channel/types.d.ts +80 -0
  38. package/dist/src/channel/types.d.ts.map +1 -0
  39. package/dist/src/channel/types.js +3 -0
  40. package/dist/src/channel/types.js.map +1 -0
  41. package/dist/src/core/index.d.ts +5 -0
  42. package/dist/src/core/index.d.ts.map +1 -0
  43. package/dist/src/core/index.js +3 -0
  44. package/dist/src/core/index.js.map +1 -0
  45. package/dist/src/core/register-identity.d.ts +58 -0
  46. package/dist/src/core/register-identity.d.ts.map +1 -0
  47. package/dist/src/core/register-identity.js +251 -0
  48. package/dist/src/core/register-identity.js.map +1 -0
  49. package/dist/src/core/task-api.d.ts +31 -0
  50. package/dist/src/core/task-api.d.ts.map +1 -0
  51. package/dist/src/core/task-api.js +116 -0
  52. package/dist/src/core/task-api.js.map +1 -0
  53. package/dist/src/core/urls.d.ts +33 -0
  54. package/dist/src/core/urls.d.ts.map +1 -0
  55. package/dist/src/core/urls.js +40 -0
  56. package/dist/src/core/urls.js.map +1 -0
  57. package/dist/src/tools/get-plugin-profile.d.ts +7 -0
  58. package/dist/src/tools/get-plugin-profile.d.ts.map +1 -0
  59. package/dist/src/tools/get-plugin-profile.js +132 -0
  60. package/dist/src/tools/get-plugin-profile.js.map +1 -0
  61. package/dist/src/tools/grab-task.d.ts +7 -0
  62. package/dist/src/tools/grab-task.d.ts.map +1 -0
  63. package/dist/src/tools/grab-task.js +100 -0
  64. package/dist/src/tools/grab-task.js.map +1 -0
  65. package/dist/src/tools/list-tasks.d.ts +7 -0
  66. package/dist/src/tools/list-tasks.d.ts.map +1 -0
  67. package/dist/src/tools/list-tasks.js +92 -0
  68. package/dist/src/tools/list-tasks.js.map +1 -0
  69. package/dist/src/tools/propose-registration.d.ts +14 -0
  70. package/dist/src/tools/propose-registration.d.ts.map +1 -0
  71. package/dist/src/tools/propose-registration.js +103 -0
  72. package/dist/src/tools/propose-registration.js.map +1 -0
  73. package/dist/src/tools/register-identity.d.ts +11 -0
  74. package/dist/src/tools/register-identity.d.ts.map +1 -0
  75. package/dist/src/tools/register-identity.js +101 -0
  76. package/dist/src/tools/register-identity.js.map +1 -0
  77. package/dist/src/tools/submit-deliverable.d.ts +17 -0
  78. package/dist/src/tools/submit-deliverable.d.ts.map +1 -0
  79. package/dist/src/tools/submit-deliverable.js +215 -0
  80. package/dist/src/tools/submit-deliverable.js.map +1 -0
  81. package/dist/src/tools/upload-artifact.d.ts +14 -0
  82. package/dist/src/tools/upload-artifact.d.ts.map +1 -0
  83. package/dist/src/tools/upload-artifact.js +166 -0
  84. package/dist/src/tools/upload-artifact.js.map +1 -0
  85. package/dist/src/utils/file-lock.d.ts +4 -0
  86. package/dist/src/utils/file-lock.d.ts.map +1 -0
  87. package/dist/src/utils/file-lock.js +43 -0
  88. package/dist/src/utils/file-lock.js.map +1 -0
  89. package/dist/src/utils/profile.d.ts +17 -0
  90. package/dist/src/utils/profile.d.ts.map +1 -0
  91. package/dist/src/utils/profile.js +26 -0
  92. package/dist/src/utils/profile.js.map +1 -0
  93. package/dist/src/utils/session.d.ts +3 -0
  94. package/dist/src/utils/session.d.ts.map +1 -0
  95. package/dist/src/utils/session.js +26 -0
  96. package/dist/src/utils/session.js.map +1 -0
  97. package/package.json +17 -5
  98. package/.env.example +0 -23
  99. package/channel/346/265/201/347/250/213/345/233/276.md +0 -477
  100. package/index.ts +0 -198
  101. package/src/channel/config.ts +0 -27
  102. package/src/channel/connection.ts +0 -341
  103. package/src/channel/dispatcher.ts +0 -374
  104. package/src/channel/index.ts +0 -173
  105. package/src/channel/logger.ts +0 -36
  106. package/src/channel/protocol.ts +0 -265
  107. package/src/channel/registrar.ts +0 -172
  108. package/src/channel/types.ts +0 -102
  109. package/src/core/index.ts +0 -13
  110. package/src/core/register-identity.ts +0 -326
  111. package/src/core/task-api.ts +0 -168
  112. package/src/core/urls.ts +0 -52
  113. package/src/prompt/job.md +0 -21
  114. package/src/tools/get-plugin-profile.ts +0 -152
  115. package/src/tools/grab-task.ts +0 -133
  116. package/src/tools/list-tasks.ts +0 -135
  117. package/src/tools/propose-registration.ts +0 -116
  118. package/src/tools/register-identity.ts +0 -121
  119. package/src/tools/submit-deliverable.ts +0 -268
  120. package/src/tools/upload-artifact.ts +0 -222
  121. package/src/utils/file-lock.ts +0 -43
  122. package/src/utils/profile.ts +0 -45
  123. package/src/utils/session.ts +0 -30
  124. package/tests/profile.test.ts +0 -70
  125. package/tests/session.test.ts +0 -53
  126. package/tsconfig.json +0 -49
  127. package/vitest.config.ts +0 -26
@@ -1,265 +0,0 @@
1
- import type {
2
- OpenResponsesEvent,
3
- ResponseInProgressEvent,
4
- OutputItemAddedEvent,
5
- OutputTextDeltaEvent,
6
- ContentPartDoneEvent,
7
- ResponseCompletedEvent,
8
- ResponseFailedEvent,
9
- RequestContent,
10
- } from "./types.js";
11
- import { TEXT_CHUNK_SIZE } from "./config.js";
12
-
13
- // ── Topics ────────────────────────────────────────────────────────────────────
14
-
15
- export const TOPIC_BOT_MESSAGES = "/v1.0/im/bot/messages";
16
- export const TOPIC_USER_MESSAGES = "/v1.0/im/user/messages";
17
-
18
- // ── Helpers ───────────────────────────────────────────────────────────────────
19
-
20
- function generateId(prefix: string): string {
21
- return `${prefix}_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
22
- }
23
-
24
- function isoNow(): string {
25
- return new Date().toISOString();
26
- }
27
-
28
- // ── Inbound Parsing ───────────────────────────────────────────────────────────
29
-
30
- export function extractContentFromInput(input: unknown[]): string {
31
- const messageParts: string[] = [];
32
-
33
- for (const item of input) {
34
- if (!item || !Array.isArray((item as { content?: unknown }).content) || (item as { content: unknown[] }).content.length === 0) {
35
- continue;
36
- }
37
-
38
- const parts: string[] = [];
39
- for (const part of (item as { content: unknown[] }).content) {
40
- if (!part || typeof part !== "object") continue;
41
- const p = part as Record<string, unknown>;
42
-
43
- switch (p["type"]) {
44
- case "input_text": {
45
- const text = p["text"];
46
- if (text && typeof text === "string" && text.trim()) {
47
- parts.push(`> ${text}`);
48
- }
49
- break;
50
- }
51
- case "input_file": {
52
- const filename = typeof p["filename"] === "string" ? p["filename"] : "file";
53
- const url = (p["file_url"] || p["url"]) as string | undefined;
54
- if (url) {
55
- parts.push(`[${filename}](${url})`);
56
- } else if (typeof p["file_id"] === "string") {
57
- parts.push(`[${filename}](file:${p["file_id"]})`);
58
- }
59
- break;
60
- }
61
- case "input_image": {
62
- const filename = typeof p["filename"] === "string" ? p["filename"] : "image";
63
- const url = (p["image_url"] || p["url"]) as string | undefined;
64
- if (url) {
65
- parts.push(`![${filename}](${url})`);
66
- } else if (typeof p["file_id"] === "string") {
67
- parts.push(`![${filename}](file:${p["file_id"]})`);
68
- }
69
- break;
70
- }
71
- }
72
- }
73
-
74
- if (parts.length > 0) {
75
- messageParts.push(parts.join("\n\n"));
76
- }
77
- }
78
-
79
- return messageParts.join("\n\n---\n\n");
80
- }
81
-
82
- export function parseRequest(rawMessage: string): RequestContent {
83
- let request: Record<string, unknown>;
84
- try {
85
- request = JSON.parse(rawMessage) as Record<string, unknown>;
86
- } catch (err) {
87
- throw new Error(`Failed to parse request JSON: ${(err as Error).message}`);
88
- }
89
-
90
- const input = request["input"];
91
- if (!Array.isArray(input) || input.length === 0) {
92
- throw new Error("Invalid request: missing or empty input array");
93
- }
94
-
95
- const content = extractContentFromInput(input);
96
- if (!content.trim()) {
97
- throw new Error("Invalid request: no extractable content in input");
98
- }
99
-
100
- const meta = request["metadata"] as Record<string, unknown> | undefined;
101
- const sessionId =
102
- meta?.["session_id"] && typeof meta["session_id"] === "string"
103
- ? meta["session_id"]
104
- : generateId("msg");
105
-
106
- const messageId =
107
- meta?.["message_id"] && typeof meta["message_id"] === "string"
108
- ? meta["message_id"]
109
- : generateId("msg");
110
-
111
- return {
112
- content,
113
- messageId,
114
- sessionId,
115
- topic: TOPIC_USER_MESSAGES,
116
- model: typeof request["model"] === "string" ? request["model"] : undefined,
117
- };
118
- }
119
-
120
- // ── Envelope Parsing ──────────────────────────────────────────────────────────
121
-
122
- export function parseEnvelope(rawMessage: string): OpenResponsesEvent {
123
- let envelope: Record<string, unknown>;
124
- try {
125
- envelope = JSON.parse(rawMessage) as Record<string, unknown>;
126
- } catch (err) {
127
- throw new Error(`Failed to parse envelope: ${(err as Error).message}`);
128
- }
129
-
130
- if (envelope["type"] !== "MESSAGE") {
131
- throw new Error(`Invalid envelope: expected type "MESSAGE", got "${envelope["type"]}"`);
132
- }
133
-
134
- const data = envelope["data"];
135
- if (typeof data !== "string") {
136
- throw new Error("Invalid envelope: data must be a string");
137
- }
138
-
139
- const event = JSON.parse(data) as OpenResponsesEvent;
140
- if (!event.type || !event.response_id) {
141
- throw new Error("Invalid event: missing type or response_id");
142
- }
143
-
144
- return event;
145
- }
146
-
147
- // ── Serialization ─────────────────────────────────────────────────────────────
148
-
149
- export function createEnvelope(event: OpenResponsesEvent): string {
150
- return JSON.stringify(event);
151
- }
152
-
153
- // ── Event Factories ───────────────────────────────────────────────────────────
154
-
155
- export function createInProgressEvent(responseId: string, sessionId?: string): ResponseInProgressEvent {
156
- const event: ResponseInProgressEvent & { metadata?: { session_id: string } } = {
157
- type: "response.in_progress",
158
- response_id: responseId,
159
- status: "in_progress",
160
- timestamp: isoNow(),
161
- };
162
- if (sessionId) event.metadata = { session_id: sessionId };
163
- return event;
164
- }
165
-
166
- export function createOutputItemAddedEvent(
167
- responseId: string,
168
- itemId: string,
169
- index = 0,
170
- ): OutputItemAddedEvent {
171
- return {
172
- type: "response.output_item.added",
173
- response_id: responseId,
174
- item: {
175
- id: itemId,
176
- type: "message",
177
- status: "in_progress",
178
- role: "assistant",
179
- content: [{ type: "output_text", status: "in_progress", text: "" }],
180
- },
181
- index,
182
- timestamp: isoNow(),
183
- };
184
- }
185
-
186
- export function createOutputTextDeltaEvent(
187
- responseId: string,
188
- itemId: string,
189
- contentIndex: number,
190
- text: string,
191
- ): OutputTextDeltaEvent {
192
- return {
193
- type: "response.output_text.delta",
194
- response_id: responseId,
195
- item_id: itemId,
196
- content_index: contentIndex,
197
- delta: { text },
198
- timestamp: isoNow(),
199
- };
200
- }
201
-
202
- export function createContentPartDoneEvent(
203
- responseId: string,
204
- itemId: string,
205
- contentIndex: number,
206
- ): ContentPartDoneEvent {
207
- return {
208
- type: "response.content_part.done",
209
- response_id: responseId,
210
- item_id: itemId,
211
- content_index: contentIndex,
212
- status: "completed",
213
- timestamp: isoNow(),
214
- };
215
- }
216
-
217
- export function createCompletedEvent(responseId: string, sessionId?: string): ResponseCompletedEvent {
218
- const event: ResponseCompletedEvent & { metadata?: { session_id: string } } = {
219
- type: "response.completed",
220
- response_id: responseId,
221
- status: "completed",
222
- timestamp: isoNow(),
223
- };
224
- if (sessionId) event.metadata = { session_id: sessionId };
225
- return event;
226
- }
227
-
228
- export function createFailedEvent(
229
- responseId: string,
230
- code: string,
231
- message: string,
232
- details: unknown = null,
233
- sessionId?: string,
234
- ): ResponseFailedEvent {
235
- const event: ResponseFailedEvent & { metadata?: { session_id: string } } = {
236
- type: "response.failed",
237
- response_id: responseId,
238
- status: "failed",
239
- error: { code, message, details },
240
- timestamp: isoNow(),
241
- };
242
- if (sessionId) event.metadata = { session_id: sessionId };
243
- return event;
244
- }
245
-
246
- // ── Text → Event Sequence ─────────────────────────────────────────────────────
247
-
248
- export function textToEventSequence(text: string, responseId?: string): OpenResponsesEvent[] {
249
- const respId = responseId ?? generateId("resp");
250
- const itemId = generateId("item");
251
-
252
- const events: OpenResponsesEvent[] = [
253
- createInProgressEvent(respId),
254
- createOutputItemAddedEvent(respId, itemId),
255
- ];
256
-
257
- for (let i = 0; i < text.length; i += TEXT_CHUNK_SIZE) {
258
- events.push(createOutputTextDeltaEvent(respId, itemId, 0, text.substring(i, i + TEXT_CHUNK_SIZE)));
259
- }
260
-
261
- events.push(createContentPartDoneEvent(respId, itemId, 0));
262
- events.push(createCompletedEvent(respId));
263
-
264
- return events;
265
- }
@@ -1,172 +0,0 @@
1
- import { VALID_SCENE_TAG_IDS, SCENE_TAGS } from "../core/register-identity.js";
2
- import { setAgentRunning, getPendingRegistration } from "./registration-store.js";
3
- import type { DebugLogger } from "./logger.js";
4
-
5
- // ── Registration prompts ──────────────────────────────────────────────────────
6
-
7
- const SCENE_TAG_SUMMARY = Object.entries(SCENE_TAGS)
8
- .map(([, group]) =>
9
- Object.entries(group.children)
10
- .map(([id, label]) => ` ${id}: ${label}`)
11
- .join("\n"),
12
- )
13
- .join("\n");
14
-
15
- /**
16
- * System prompt instructs the AI to decide sensible defaults autonomously and
17
- * call `insta_propose_registration` to store them for user review.
18
- *
19
- * The AI must NOT call `insta_register_identity` directly — the actual
20
- * registration happens only after the user confirms via the gateway UI.
21
- */
22
- const REGISTRATION_SYSTEM_PROMPT = `
23
- 你是 InstaClaw 频道配置向导。InstaClaw 是一个 AI 代理接单平台。
24
-
25
- 本次调用是插件在首次启动时自动触发的。你的任务是根据当前 Agent 的上下文,推断合理的注册默认参数,
26
- 然后调用 insta_propose_registration 将这些参数暂存,由用户在控制面板中审阅并最终确认。
27
-
28
- 【重要】不要调用 insta_register_identity,不要直接完成注册。只调用 insta_propose_registration。
29
-
30
- 参数推断规则:
31
- - name:根据 Agent 名称或用途取一个简洁有辨识度的名称
32
- - avatar:使用占位头像,例如 https://api.dicebear.com/7.x/bottts/svg?seed=instaclaw
33
- - description:简短描述当前 Agent 的主要能力(1-2 句话)
34
- - hourly_rate:默认设为 100(单位:元)
35
- - scene_tags:从以下合法 ID 中选 1-3 个最符合当前 Agent 定位的:
36
- ${SCENE_TAG_SUMMARY}
37
- - custom_tags:可留空数组 []
38
- - instance_type:固定填 0(本地实例)
39
-
40
- 行动要求:
41
- 1. 根据上述规则自主决定每个参数的值
42
- 2. 调用 insta_propose_registration 提交提案(参数将暂存,等待用户确认)
43
- 3. 不要输出多余的解释,直接执行工具调用
44
- `.trim();
45
-
46
- const REGISTRATION_INITIAL_PROMPT =
47
- "InstaClaw 频道首次启动,尚未完成注册。请根据当前 Agent 上下文推断合理的默认注册参数,调用 insta_propose_registration 提交提案,用户将在控制面板中确认后完成注册。";
48
-
49
- // ── Types ─────────────────────────────────────────────────────────────────────
50
-
51
- export type RegistrarStatus = "triggered" | "unavailable" | "error";
52
-
53
- export interface RegistrarResult {
54
- status: RegistrarStatus;
55
- error?: string;
56
- }
57
-
58
- // ── Runtime type ──────────────────────────────────────────────────────────────
59
-
60
- type ChannelRuntimeWithReply = {
61
- reply?: {
62
- dispatchReplyWithBufferedBlockDispatcher?: (opts: {
63
- ctx: Record<string, unknown>;
64
- cfg: unknown;
65
- replyOptions?: {
66
- abortSignal?: AbortSignal;
67
- onPartialReply?: (payload: { text?: string }) => void;
68
- };
69
- dispatcherOptions?: {
70
- deliver?: (payload: { text?: string }) => Promise<void>;
71
- onError?: (err: unknown) => void;
72
- };
73
- }) => Promise<void>;
74
- };
75
- };
76
-
77
- // ── Trigger ───────────────────────────────────────────────────────────────────
78
-
79
- /**
80
- * Fire-and-forget: uses `channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher`
81
- * to launch a synthetic AI conversation that auto-calls `insta_register_identity`.
82
- *
83
- * Unlike `subagent.run`, `dispatchReplyWithBufferedBlockDispatcher` is available
84
- * at any point during the channel lifecycle, including inside `startAccount`.
85
- *
86
- * The AI response text is discarded — only the tool call side-effect matters
87
- * (writing the profile file). The polling loop in `startAccount` detects the
88
- * resulting profile and establishes the WebSocket connection.
89
- */
90
- export async function triggerRegistrationAgent(
91
- channelRuntime: unknown,
92
- cfg: unknown,
93
- logger: DebugLogger,
94
- accountId?: string,
95
- ): Promise<RegistrarResult> {
96
- const runtime = channelRuntime as ChannelRuntimeWithReply | undefined;
97
-
98
- if (!runtime?.reply?.dispatchReplyWithBufferedBlockDispatcher) {
99
- logger.warn(
100
- "channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher not available. " +
101
- "Register manually by calling the insta_register_identity tool.",
102
- );
103
- return { status: "unavailable" };
104
- }
105
-
106
- const msgCtx: Record<string, unknown> = {
107
- Body: REGISTRATION_INITIAL_PROMPT,
108
- AccountId: accountId ?? "default",
109
- SessionKey: `instaclaw:${accountId ?? "default"}:registration`,
110
- SystemPrompt: REGISTRATION_SYSTEM_PROMPT,
111
- };
112
-
113
- try {
114
- // Mark in-flight BEFORE the async dispatch so the polling loop
115
- // immediately sees "running" on the very next tick.
116
- setAgentRunning(true);
117
-
118
- // Fire-and-forget: errors from the AI run are caught below and logged,
119
- // but do not block the polling loop.
120
- void runtime.reply.dispatchReplyWithBufferedBlockDispatcher({
121
- ctx: msgCtx,
122
- cfg,
123
- replyOptions: {
124
- onPartialReply: (_payload) => {
125
- // Intentionally discard streaming text — we only care about tool calls.
126
- },
127
- },
128
- dispatcherOptions: {
129
- deliver: async (_payload) => {
130
- // Bug 2 fix: always clear the running flag so startAccount can
131
- // re-trigger if the AI completed without calling insta_propose_registration.
132
- setAgentRunning(false);
133
-
134
- if (getPendingRegistration()) {
135
- logger.info("Registration agent completed — proposal stored, waiting for user confirmation");
136
- } else {
137
- logger.warn(
138
- "Registration agent completed but no proposal was created. " +
139
- "startAccount will re-trigger on the next poll cycle.",
140
- );
141
- }
142
- },
143
- onError: (err: unknown) => {
144
- // Clear the running flag so the polling loop can recover.
145
- setAgentRunning(false);
146
- logger.error(
147
- "Registration agent dispatch error",
148
- err instanceof Error ? err : new Error(String(err)),
149
- );
150
- },
151
- },
152
- }).catch((err: unknown) => {
153
- // Hard rejection (e.g. runtime unavailable mid-flight): also clear flag.
154
- setAgentRunning(false);
155
- logger.error(
156
- "Registration agent dispatch rejected",
157
- err instanceof Error ? err : new Error(String(err)),
158
- );
159
- });
160
-
161
- logger.info("Registration agent dispatch triggered via dispatchReplyWithBufferedBlockDispatcher");
162
- return { status: "triggered" };
163
- } catch (err) {
164
- // Synchronous throw before dispatch could start — clear flag.
165
- setAgentRunning(false);
166
- const message = err instanceof Error ? err.message : String(err);
167
- logger.error("Failed to trigger registration agent dispatch", err instanceof Error ? err : undefined);
168
- return { status: "error", error: message };
169
- }
170
- }
171
-
172
- export { VALID_SCENE_TAG_IDS };
@@ -1,102 +0,0 @@
1
- // ── Connection ───────────────────────────────────────────────────────────────
2
-
3
- export type ConnectionState = "connecting" | "connected" | "disconnected" | "reconnecting";
4
-
5
- export interface ConnectionConfig {
6
- wsUrl: string;
7
- clientId: string;
8
- clientSecret: string;
9
- heartbeatInterval: number;
10
- reconnectMaxAttempts?: number;
11
- }
12
-
13
- // ── WebSocket Envelope (open-responses §7) ────────────────────────────────────
14
-
15
- export interface WebSocketEnvelope {
16
- type: "MESSAGE";
17
- headers: {
18
- messageId: string;
19
- topic: string;
20
- [key: string]: string;
21
- };
22
- data: string;
23
- }
24
-
25
- // ── Open Responses Event Types (open-responses §5–§6) ─────────────────────────
26
-
27
- export interface BaseEvent {
28
- type: string;
29
- response_id: string;
30
- timestamp: string;
31
- }
32
-
33
- export interface ResponseInProgressEvent extends BaseEvent {
34
- type: "response.in_progress";
35
- status: "in_progress";
36
- }
37
-
38
- export interface OutputItemAddedEvent extends BaseEvent {
39
- type: "response.output_item.added";
40
- item: Item;
41
- index: number;
42
- }
43
-
44
- export interface OutputTextDeltaEvent extends BaseEvent {
45
- type: "response.output_text.delta";
46
- item_id: string;
47
- content_index: number;
48
- delta: { text: string };
49
- }
50
-
51
- export interface ContentPartDoneEvent extends BaseEvent {
52
- type: "response.content_part.done";
53
- item_id: string;
54
- content_index: number;
55
- status: "completed";
56
- }
57
-
58
- export interface ResponseCompletedEvent extends BaseEvent {
59
- type: "response.completed";
60
- status: "completed";
61
- }
62
-
63
- export interface ResponseFailedEvent extends BaseEvent {
64
- type: "response.failed";
65
- status: "failed";
66
- error: { code: string; message: string; details: unknown };
67
- }
68
-
69
- export type OpenResponsesEvent =
70
- | ResponseInProgressEvent
71
- | OutputItemAddedEvent
72
- | OutputTextDeltaEvent
73
- | ContentPartDoneEvent
74
- | ResponseCompletedEvent
75
- | ResponseFailedEvent;
76
-
77
- // ── Data Models ───────────────────────────────────────────────────────────────
78
-
79
- export interface ContentPart {
80
- type: "output_text";
81
- status: "in_progress" | "completed";
82
- text: string;
83
- }
84
-
85
- export interface Item {
86
- id: string;
87
- type: "message" | "function_call" | "function_call_output" | "reasoning";
88
- status: "in_progress" | "completed" | "incomplete" | "failed";
89
- role?: "assistant" | "user";
90
- content: ContentPart[];
91
- }
92
-
93
- // ── Inbound Request ───────────────────────────────────────────────────────────
94
-
95
- export interface RequestContent {
96
- content: string;
97
- messageId: string;
98
- topic: string;
99
- sessionId: string;
100
- model?: string;
101
- [key: string]: unknown;
102
- }
package/src/core/index.ts DELETED
@@ -1,13 +0,0 @@
1
- export {
2
- registerIdentity,
3
- SCENE_TAGS,
4
- VALID_SCENE_TAG_IDS,
5
- } from "./register-identity.js";
6
- export type {
7
- RegisterIdentityParams,
8
- RegisterIdentityResponse,
9
- RegisterIdentityResult,
10
- } from "./register-identity.js";
11
-
12
- export { getInstaUrl } from "./urls.js";
13
- export type { UrlKey } from "./urls.js";