@questionbase/deskfree 0.3.0-alpha.2 → 0.3.0-alpha.21
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/README.md +24 -14
- package/dist/index.d.ts +745 -6
- package/dist/index.js +9192 -18
- package/dist/index.js.map +1 -1
- package/package.json +8 -9
- package/skills/deskfree/SKILL.md +510 -221
- package/skills/deskfree/references/tools.md +144 -0
- package/dist/channel.d.ts +0 -3
- package/dist/channel.d.ts.map +0 -1
- package/dist/channel.js +0 -505
- package/dist/channel.js.map +0 -1
- package/dist/client.d.ts +0 -143
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -246
- package/dist/client.js.map +0 -1
- package/dist/deliver.d.ts +0 -22
- package/dist/deliver.d.ts.map +0 -1
- package/dist/deliver.js +0 -350
- package/dist/deliver.js.map +0 -1
- package/dist/gateway.d.ts +0 -13
- package/dist/gateway.d.ts.map +0 -1
- package/dist/gateway.js +0 -836
- package/dist/gateway.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/llm-definitions.d.ts +0 -117
- package/dist/llm-definitions.d.ts.map +0 -1
- package/dist/llm-definitions.js +0 -121
- package/dist/llm-definitions.js.map +0 -1
- package/dist/offline-queue.d.ts +0 -45
- package/dist/offline-queue.d.ts.map +0 -1
- package/dist/offline-queue.js +0 -109
- package/dist/offline-queue.js.map +0 -1
- package/dist/paths.d.ts +0 -10
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js +0 -29
- package/dist/paths.js.map +0 -1
- package/dist/runtime.d.ts +0 -17
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js +0 -24
- package/dist/runtime.js.map +0 -1
- package/dist/tools.d.ts +0 -23
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -437
- package/dist/tools.js.map +0 -1
- package/dist/types.d.ts +0 -438
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/workspace.d.ts +0 -18
- package/dist/workspace.d.ts.map +0 -1
- package/dist/workspace.js +0 -83
- package/dist/workspace.js.map +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# DeskFree Tools — Full Parameter Reference
|
|
2
|
+
|
|
3
|
+
## Orchestrator Tools (10)
|
|
4
|
+
|
|
5
|
+
### `deskfree_state`
|
|
6
|
+
Get full workspace snapshot — all tasks, recently done tasks, active initiatives, current ways of working, and pending evaluations.
|
|
7
|
+
|
|
8
|
+
| Parameter | Type | Required | Description |
|
|
9
|
+
|-----------|------|----------|-------------|
|
|
10
|
+
| *(none)* | — | — | — |
|
|
11
|
+
|
|
12
|
+
**Returns:**
|
|
13
|
+
- `tasks` — active tasks array
|
|
14
|
+
- `recentlyDone` — recently completed tasks
|
|
15
|
+
- `waysOfWorking` — global ways of working (string or null)
|
|
16
|
+
- `pendingEvaluations` — array of `{taskId, taskNumber, title, initiativeId?}`
|
|
17
|
+
- `initiatives` — active initiatives with `{id, title, status, content, contentVersion, taskCount, activeTaskCount}`
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
### `deskfree_start_task`
|
|
22
|
+
Claim a `bot` task → moves to `bot` (is_working=true). Returns full context.
|
|
23
|
+
|
|
24
|
+
| Parameter | Type | Required | Description |
|
|
25
|
+
|-----------|------|----------|-------------|
|
|
26
|
+
| `taskId` | string | Yes | Task UUID to claim |
|
|
27
|
+
|
|
28
|
+
**Returns:** Full task context — instructions, current deliverable, message history, and `parentContext` (title, deliverable, instructions of the parent task if this was suggested by another task). Use this to populate sub-agent spawn prompts.
|
|
29
|
+
|
|
30
|
+
**Errors:** 404 if task not `bot` or doesn't exist. 409 if already claimed.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
### `deskfree_update_deliverable`
|
|
35
|
+
Update task deliverable. Build incrementally as you work.
|
|
36
|
+
|
|
37
|
+
| Parameter | Type | Required | Description |
|
|
38
|
+
|-----------|------|----------|-------------|
|
|
39
|
+
| `taskId` | string | Yes | Task UUID |
|
|
40
|
+
| `deliverable` | string | Yes | Full markdown deliverable content (replaces previous) |
|
|
41
|
+
|
|
42
|
+
**Note:** Each call replaces the entire deliverable. Always send the complete current version, not just new additions.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
### `deskfree_complete_task`
|
|
47
|
+
Finish a task → moves to `human`.
|
|
48
|
+
|
|
49
|
+
| Parameter | Type | Required | Description |
|
|
50
|
+
|-----------|------|----------|-------------|
|
|
51
|
+
| `taskId` | string | Yes | Task UUID |
|
|
52
|
+
| `outcome` | string | Yes | `done` (work complete) or `blocked` (need human input) |
|
|
53
|
+
|
|
54
|
+
**Important:** If `blocked`, send a message explaining WHY before calling this.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
### `deskfree_send_message`
|
|
59
|
+
Send a message in the task thread (progress update, question, status report).
|
|
60
|
+
|
|
61
|
+
| Parameter | Type | Required | Description |
|
|
62
|
+
|-----------|------|----------|-------------|
|
|
63
|
+
| `content` | string | No | Message content. Required unless `suggestions` is provided. |
|
|
64
|
+
| `taskId` | string | No | Task UUID (optional — auto-threaded to active task if omitted) |
|
|
65
|
+
| `suggestions` | array | No | List of tasks to suggest for human review (1-10). Prefer `deskfree_suggest_tasks` for richer suggestions with estimatedTokens and dependencies. |
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### `deskfree_suggest_tasks`
|
|
70
|
+
Suggest tasks for human approval. Creates tasks with `suggested` status. Can also propose new initiatives.
|
|
71
|
+
|
|
72
|
+
| Parameter | Type | Required | Description |
|
|
73
|
+
|-----------|------|----------|-------------|
|
|
74
|
+
| `suggestions` | array | Yes | Array of task suggestions (1-20) |
|
|
75
|
+
| `suggestions[].title` | string | Yes | Task title — short, action-oriented (max 200 chars) |
|
|
76
|
+
| `suggestions[].instructions` | string | No | Detailed instructions: what to do, why, what done looks like, constraints |
|
|
77
|
+
| `suggestions[].estimatedTokens` | number | No | Estimated token cost for completing this task |
|
|
78
|
+
| `suggestions[].dependsOn` | string[] | No | Task IDs this depends on (blocks claiming until those are done) |
|
|
79
|
+
| `suggestions[].initiativeId` | string | No | Link task to an existing active initiative |
|
|
80
|
+
| `initiativeSuggestions` | array | No | Propose new initiatives (0-5) |
|
|
81
|
+
| `initiativeSuggestions[].title` | string | Yes | Initiative title (max 200 chars) |
|
|
82
|
+
| `initiativeSuggestions[].content` | string | Yes | Initial initiative content (markdown — current state, approach, next priorities) |
|
|
83
|
+
| `initiativeSuggestions[].taskRefs` | number[] | No | Indexes into `suggestions[]` to auto-link when approved |
|
|
84
|
+
| `parentTaskId` | string | No | Parent task ID — set when suggesting follow-ups from within a task |
|
|
85
|
+
|
|
86
|
+
**Returns:** `{ suggestionIds: string[], initiativeSuggestionIds?: string[] }`
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
### `deskfree_complete_and_suggest`
|
|
91
|
+
Complete the current task AND suggest follow-up tasks in one atomic call.
|
|
92
|
+
|
|
93
|
+
| Parameter | Type | Required | Description |
|
|
94
|
+
|-----------|------|----------|-------------|
|
|
95
|
+
| `taskId` | string | Yes | Task UUID to complete |
|
|
96
|
+
| `outcome` | string | Yes | `done` or `blocked` |
|
|
97
|
+
| `suggestions` | array | No | Follow-up task suggestions (0-20) |
|
|
98
|
+
| `suggestions[].title` | string | Yes | Task title (max 200 chars) |
|
|
99
|
+
| `suggestions[].instructions` | string | No | Detailed instructions |
|
|
100
|
+
| `suggestions[].estimatedTokens` | number | No | Estimated token cost |
|
|
101
|
+
| `suggestions[].dependsOnTaskIds` | string[] | No | Task IDs this depends on |
|
|
102
|
+
| `suggestions[].initiativeId` | string | No | Link to existing initiative |
|
|
103
|
+
| `initiativeSuggestions` | array | No | Propose new initiatives (same schema as deskfree_suggest_tasks) |
|
|
104
|
+
|
|
105
|
+
**Returns:** Updated task object + `suggestionIds` array (if suggestions were created) + `initiativeSuggestionIds` (if initiatives were suggested).
|
|
106
|
+
|
|
107
|
+
**Note:** Deliverable required for outcome `done`. Task moves to `human` for review.
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
### `deskfree_claim_evaluation`
|
|
112
|
+
Claim a pending evaluation. Atomically sets `isWorking=true` where `evaluationPending=true` and `isWorking=false`. Returns null if already claimed.
|
|
113
|
+
|
|
114
|
+
| Parameter | Type | Required | Description |
|
|
115
|
+
|-----------|------|----------|-------------|
|
|
116
|
+
| `taskId` | string | Yes | Task UUID from `pendingEvaluations` list |
|
|
117
|
+
|
|
118
|
+
**Returns:** `{ task, waysOfWorking, currentVersion, messages, initiative? }` — full evaluation context including initiative data (if task is linked to one), or `null` if already claimed.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
### `deskfree_submit_evaluation`
|
|
123
|
+
Submit the result of an evaluation. Supports dual output: global ways of working + initiative content. Always call this after `deskfree_claim_evaluation`.
|
|
124
|
+
|
|
125
|
+
| Parameter | Type | Required | Description |
|
|
126
|
+
|-----------|------|----------|-------------|
|
|
127
|
+
| `taskId` | string | Yes | Task UUID being evaluated |
|
|
128
|
+
| `reasoning` | string | Yes | Explanation of your analysis — what you learned |
|
|
129
|
+
| `globalWoW` | object | Yes | Global ways of working update |
|
|
130
|
+
| `globalWoW.hasChanges` | boolean | Yes | Whether global WoW should be updated |
|
|
131
|
+
| `globalWoW.updatedContent` | string | No | Full updated global WoW markdown (required if hasChanges=true) |
|
|
132
|
+
| `initiative` | object | No | Initiative content update (only if task has initiative_id) |
|
|
133
|
+
| `initiative.hasChanges` | boolean | Yes | Whether initiative content should be updated |
|
|
134
|
+
| `initiative.updatedContent` | string | No | Full updated initiative content markdown (required if hasChanges=true) |
|
|
135
|
+
|
|
136
|
+
**Returns:** `{ success, globalVersion?, initiativeVersion? }`
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Worker Tools (4 — sub-agents only)
|
|
141
|
+
|
|
142
|
+
Sub-agents receive: `deskfree_update_deliverable`, `deskfree_complete_task`, `deskfree_send_message`, `deskfree_submit_evaluation`
|
|
143
|
+
|
|
144
|
+
They **cannot** use: `deskfree_state`, `deskfree_suggest_tasks`, `deskfree_start_task`, `deskfree_claim_evaluation`
|
package/dist/channel.d.ts
DELETED
package/dist/channel.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAGV,aAAa,EAId,MAAM,SAAS,CAAC;AAMjB,eAAO,MAAM,cAAc,EAAE,aAgjB5B,CAAC"}
|
package/dist/channel.js
DELETED
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
import { DeskFreeClient } from './client';
|
|
2
|
-
import { getActiveTaskId, startDeskFreeConnection } from './gateway';
|
|
3
|
-
import { CHANNEL_HINTS, CHANNEL_META, STATUS_MESSAGES, } from './llm-definitions';
|
|
4
|
-
import { getDeskFreeRuntime } from './runtime';
|
|
5
|
-
function getChannelConfig(cfg) {
|
|
6
|
-
return cfg?.channels?.deskfree ?? null;
|
|
7
|
-
}
|
|
8
|
-
export const deskFreePlugin = {
|
|
9
|
-
id: 'deskfree',
|
|
10
|
-
meta: CHANNEL_META,
|
|
11
|
-
capabilities: {
|
|
12
|
-
text: true,
|
|
13
|
-
media: false,
|
|
14
|
-
reactions: false,
|
|
15
|
-
threads: true,
|
|
16
|
-
editing: false,
|
|
17
|
-
},
|
|
18
|
-
config: {
|
|
19
|
-
listAccountIds(cfg) {
|
|
20
|
-
const ch = getChannelConfig(cfg);
|
|
21
|
-
if (!ch)
|
|
22
|
-
return [];
|
|
23
|
-
if (ch.accounts && Object.keys(ch.accounts).length > 0) {
|
|
24
|
-
return Object.keys(ch.accounts);
|
|
25
|
-
}
|
|
26
|
-
return ['default'];
|
|
27
|
-
},
|
|
28
|
-
resolveAccount(cfg, accountId) {
|
|
29
|
-
const ch = getChannelConfig(cfg);
|
|
30
|
-
if (!ch) {
|
|
31
|
-
return {
|
|
32
|
-
accountId: accountId ?? 'default',
|
|
33
|
-
botToken: '',
|
|
34
|
-
apiUrl: '',
|
|
35
|
-
wsUrl: '',
|
|
36
|
-
userId: '',
|
|
37
|
-
enabled: false,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
const id = accountId ?? 'default';
|
|
41
|
-
const acct = id !== 'default' && ch.accounts?.[id] ? ch.accounts[id] : ch;
|
|
42
|
-
return {
|
|
43
|
-
accountId: id,
|
|
44
|
-
botToken: acct.botToken ?? '',
|
|
45
|
-
apiUrl: acct.apiUrl ?? '',
|
|
46
|
-
wsUrl: acct.wsUrl ?? '',
|
|
47
|
-
userId: acct.userId ?? '',
|
|
48
|
-
enabled: acct.enabled !== false,
|
|
49
|
-
botName: acct.botName,
|
|
50
|
-
humanName: acct.humanName,
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
isConfigured(account) {
|
|
54
|
-
return Boolean(account.botToken && account.apiUrl);
|
|
55
|
-
},
|
|
56
|
-
isEnabled(account) {
|
|
57
|
-
return account.enabled;
|
|
58
|
-
},
|
|
59
|
-
describeAccount(account) {
|
|
60
|
-
const isConfigured = Boolean(account.botToken && account.apiUrl);
|
|
61
|
-
return {
|
|
62
|
-
accountId: account.accountId,
|
|
63
|
-
enabled: account.enabled,
|
|
64
|
-
configured: isConfigured,
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
outbound: {
|
|
69
|
-
deliveryMode: 'direct',
|
|
70
|
-
chunkerMode: 'markdown',
|
|
71
|
-
textChunkLimit: 2000,
|
|
72
|
-
resolveTarget(_target, { cfg, accountId }) {
|
|
73
|
-
// Resolve to the userId configured for this account
|
|
74
|
-
const acct = deskFreePlugin.config.resolveAccount(cfg, accountId);
|
|
75
|
-
if (!acct.userId)
|
|
76
|
-
return null;
|
|
77
|
-
return { to: acct.userId };
|
|
78
|
-
},
|
|
79
|
-
async sendText(ctx) {
|
|
80
|
-
const runtime = getDeskFreeRuntime();
|
|
81
|
-
const cfg = runtime.config.loadConfig();
|
|
82
|
-
const ch = getChannelConfig(cfg);
|
|
83
|
-
if (!ch) {
|
|
84
|
-
return { channel: 'deskfree', success: false };
|
|
85
|
-
}
|
|
86
|
-
const acct = deskFreePlugin.config.resolveAccount(cfg, ctx.accountId);
|
|
87
|
-
const client = new DeskFreeClient(acct.botToken, acct.apiUrl);
|
|
88
|
-
const log = runtime.logging.createLogger('deskfree');
|
|
89
|
-
try {
|
|
90
|
-
// Use explicit threadId if present, otherwise auto-thread
|
|
91
|
-
// into the active task
|
|
92
|
-
const taskId = ctx.threadId
|
|
93
|
-
? String(ctx.threadId)
|
|
94
|
-
: (getActiveTaskId() ?? undefined);
|
|
95
|
-
await client.sendMessage({
|
|
96
|
-
content: ctx.text,
|
|
97
|
-
taskId,
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
channel: 'deskfree',
|
|
101
|
-
success: true,
|
|
102
|
-
threadId: taskId,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
catch (err) {
|
|
106
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
107
|
-
log.error(`Failed to send message: ${message}`);
|
|
108
|
-
return {
|
|
109
|
-
channel: 'deskfree',
|
|
110
|
-
success: false,
|
|
111
|
-
error: message,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
gateway: {
|
|
117
|
-
async startAccount(ctx) {
|
|
118
|
-
return startDeskFreeConnection(ctx);
|
|
119
|
-
},
|
|
120
|
-
async stopAccount(ctx) {
|
|
121
|
-
const log = ctx.log ?? getDeskFreeRuntime().logging.createLogger('deskfree');
|
|
122
|
-
log.info(`Stopping DeskFree account ${ctx.accountId}`);
|
|
123
|
-
ctx.setStatus({ running: false, lastStopAt: Date.now() });
|
|
124
|
-
},
|
|
125
|
-
async logoutAccount(ctx) {
|
|
126
|
-
const log = ctx.log ?? getDeskFreeRuntime().logging.createLogger('deskfree');
|
|
127
|
-
const runtime = ctx.runtime;
|
|
128
|
-
// Clone config immutably
|
|
129
|
-
const config = JSON.parse(JSON.stringify(ctx.cfg));
|
|
130
|
-
const channels = (config.channels ?? {});
|
|
131
|
-
const deskfree = (channels.deskfree ?? {});
|
|
132
|
-
if (ctx.accountId === 'default') {
|
|
133
|
-
delete deskfree.botToken;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
const accounts = (deskfree.accounts ?? {});
|
|
137
|
-
if (accounts[ctx.accountId]) {
|
|
138
|
-
delete accounts[ctx.accountId].botToken;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
channels.deskfree = deskfree;
|
|
142
|
-
config.channels = channels;
|
|
143
|
-
await runtime.config.writeConfigFile(config);
|
|
144
|
-
log.info(`Cleared bot token for account ${ctx.accountId}`);
|
|
145
|
-
return { cleared: true, loggedOut: true };
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
setup: {
|
|
149
|
-
applyAccountConfig(params) {
|
|
150
|
-
const { cfg, accountId, input } = params;
|
|
151
|
-
const config = cfg;
|
|
152
|
-
const channels = (config.channels ?? {});
|
|
153
|
-
const deskfree = (channels.deskfree ?? {});
|
|
154
|
-
if (accountId === 'default') {
|
|
155
|
-
deskfree.botToken = input.botToken;
|
|
156
|
-
deskfree.apiUrl = input.apiUrl;
|
|
157
|
-
deskfree.wsUrl = input.wsUrl;
|
|
158
|
-
deskfree.userId = input.userId;
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
const accounts = (deskfree.accounts ?? {});
|
|
162
|
-
accounts[accountId] = {
|
|
163
|
-
botToken: input.botToken,
|
|
164
|
-
apiUrl: input.apiUrl,
|
|
165
|
-
wsUrl: input.wsUrl,
|
|
166
|
-
userId: input.userId,
|
|
167
|
-
enabled: true,
|
|
168
|
-
};
|
|
169
|
-
deskfree.accounts = accounts;
|
|
170
|
-
}
|
|
171
|
-
// Always set top-level channel enabled
|
|
172
|
-
deskfree.enabled = true;
|
|
173
|
-
channels.deskfree = deskfree;
|
|
174
|
-
config.channels = channels;
|
|
175
|
-
// Register plugin entry with channel ID to prevent auto-enable
|
|
176
|
-
// from creating a phantom disabled entry under the NPM package ID
|
|
177
|
-
const plugins = (config.plugins ?? {});
|
|
178
|
-
const entries = (plugins.entries ?? {});
|
|
179
|
-
const existing = (entries.deskfree ?? {});
|
|
180
|
-
entries.deskfree = { ...existing, enabled: true };
|
|
181
|
-
plugins.entries = entries;
|
|
182
|
-
config.plugins = plugins;
|
|
183
|
-
return config;
|
|
184
|
-
},
|
|
185
|
-
validateInput(params) {
|
|
186
|
-
const { input } = params;
|
|
187
|
-
// Validate bot token
|
|
188
|
-
if (!input.botToken) {
|
|
189
|
-
return 'Bot token is required';
|
|
190
|
-
}
|
|
191
|
-
if (typeof input.botToken !== 'string') {
|
|
192
|
-
return 'Bot token must be a string';
|
|
193
|
-
}
|
|
194
|
-
const botTokenTrimmed = input.botToken.trim();
|
|
195
|
-
if (botTokenTrimmed !== input.botToken) {
|
|
196
|
-
return 'Bot token must not have leading or trailing whitespace';
|
|
197
|
-
}
|
|
198
|
-
if (!botTokenTrimmed.startsWith('bot_')) {
|
|
199
|
-
return 'Bot token must start with "bot_"';
|
|
200
|
-
}
|
|
201
|
-
if (botTokenTrimmed.length < 10) {
|
|
202
|
-
return 'Bot token appears to be too short (minimum 10 characters)';
|
|
203
|
-
}
|
|
204
|
-
if (botTokenTrimmed.length > 100) {
|
|
205
|
-
return 'Bot token appears to be too long (maximum 100 characters)';
|
|
206
|
-
}
|
|
207
|
-
if (!/^bot_[a-zA-Z0-9_-]+$/.test(botTokenTrimmed)) {
|
|
208
|
-
return 'Bot token contains invalid characters (only alphanumeric, underscore, and dash allowed after "bot_")';
|
|
209
|
-
}
|
|
210
|
-
// Validate API URL
|
|
211
|
-
if (!input.apiUrl) {
|
|
212
|
-
return 'API URL is required';
|
|
213
|
-
}
|
|
214
|
-
if (typeof input.apiUrl !== 'string') {
|
|
215
|
-
return 'API URL must be a string';
|
|
216
|
-
}
|
|
217
|
-
const apiUrlTrimmed = input.apiUrl.trim();
|
|
218
|
-
if (apiUrlTrimmed !== input.apiUrl) {
|
|
219
|
-
return 'API URL must not have leading or trailing whitespace';
|
|
220
|
-
}
|
|
221
|
-
try {
|
|
222
|
-
const apiUrl = new URL(apiUrlTrimmed);
|
|
223
|
-
if (apiUrl.protocol !== 'https:') {
|
|
224
|
-
return 'API URL must use HTTPS protocol for security';
|
|
225
|
-
}
|
|
226
|
-
if (!apiUrl.hostname) {
|
|
227
|
-
return 'API URL must have a valid hostname';
|
|
228
|
-
}
|
|
229
|
-
if (apiUrl.hostname === 'localhost' ||
|
|
230
|
-
apiUrl.hostname === '127.0.0.1') {
|
|
231
|
-
return 'API URL cannot use localhost (use a publicly accessible URL)';
|
|
232
|
-
}
|
|
233
|
-
if (apiUrl.pathname && !apiUrl.pathname.endsWith('/')) {
|
|
234
|
-
// Warn if path doesn't end with slash but don't fail validation
|
|
235
|
-
// since the client will normalize this
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
catch (err) {
|
|
239
|
-
const message = err instanceof Error ? err.message : 'Invalid URL format';
|
|
240
|
-
return `API URL must be a valid URL: ${message}`;
|
|
241
|
-
}
|
|
242
|
-
// Validate WebSocket URL
|
|
243
|
-
if (!input.wsUrl) {
|
|
244
|
-
return 'WebSocket URL is required';
|
|
245
|
-
}
|
|
246
|
-
if (typeof input.wsUrl !== 'string') {
|
|
247
|
-
return 'WebSocket URL must be a string';
|
|
248
|
-
}
|
|
249
|
-
const wsUrlTrimmed = input.wsUrl.trim();
|
|
250
|
-
if (wsUrlTrimmed !== input.wsUrl) {
|
|
251
|
-
return 'WebSocket URL must not have leading or trailing whitespace';
|
|
252
|
-
}
|
|
253
|
-
try {
|
|
254
|
-
const wsUrl = new URL(wsUrlTrimmed);
|
|
255
|
-
if (!['ws:', 'wss:'].includes(wsUrl.protocol)) {
|
|
256
|
-
return 'WebSocket URL must use ws:// or wss:// protocol';
|
|
257
|
-
}
|
|
258
|
-
if (!wsUrl.hostname) {
|
|
259
|
-
return 'WebSocket URL must have a valid hostname';
|
|
260
|
-
}
|
|
261
|
-
if (wsUrl.hostname === 'localhost' || wsUrl.hostname === '127.0.0.1') {
|
|
262
|
-
return 'WebSocket URL cannot use localhost (use a publicly accessible URL)';
|
|
263
|
-
}
|
|
264
|
-
// Recommend wss:// for security if using ws://
|
|
265
|
-
if (wsUrl.protocol === 'ws:' && wsUrl.hostname !== 'localhost') {
|
|
266
|
-
// This is just a recommendation, not a hard failure
|
|
267
|
-
// Most production deployments should use wss://
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
catch (err) {
|
|
271
|
-
const message = err instanceof Error ? err.message : 'Invalid URL format';
|
|
272
|
-
return `WebSocket URL must be a valid URL: ${message}`;
|
|
273
|
-
}
|
|
274
|
-
// Validate User ID
|
|
275
|
-
if (!input.userId) {
|
|
276
|
-
return 'User ID is required';
|
|
277
|
-
}
|
|
278
|
-
if (typeof input.userId !== 'string') {
|
|
279
|
-
return 'User ID must be a string';
|
|
280
|
-
}
|
|
281
|
-
const userIdTrimmed = input.userId.trim().toUpperCase();
|
|
282
|
-
if (userIdTrimmed !== input.userId.toUpperCase()) {
|
|
283
|
-
return 'User ID must not have leading or trailing whitespace and should be uppercase';
|
|
284
|
-
}
|
|
285
|
-
if (!/^[UBPT][A-Z0-9]{10}$/.test(userIdTrimmed)) {
|
|
286
|
-
const prefix = userIdTrimmed.charAt(0);
|
|
287
|
-
if (!'UBPT'.includes(prefix)) {
|
|
288
|
-
return 'User ID must start with U, B, P, or T (got: ' + prefix + ')';
|
|
289
|
-
}
|
|
290
|
-
if (userIdTrimmed.length !== 11) {
|
|
291
|
-
return `User ID must be exactly 11 characters long (got: ${userIdTrimmed.length})`;
|
|
292
|
-
}
|
|
293
|
-
return 'User ID must be a valid DeskFree ID format: one letter (U/B/P/T) + 10 alphanumeric characters (e.g. U9QF3C6X1A)';
|
|
294
|
-
}
|
|
295
|
-
return null;
|
|
296
|
-
},
|
|
297
|
-
},
|
|
298
|
-
messaging: {
|
|
299
|
-
normalizeTarget(raw) {
|
|
300
|
-
const trimmed = raw.trim();
|
|
301
|
-
if (/^[UBPT][A-Z0-9]{10}$/i.test(trimmed))
|
|
302
|
-
return `user:${trimmed}`;
|
|
303
|
-
return undefined;
|
|
304
|
-
},
|
|
305
|
-
targetResolver: {
|
|
306
|
-
hint: CHANNEL_HINTS.targetResolver,
|
|
307
|
-
looksLikeId(raw) {
|
|
308
|
-
const t = raw.trim();
|
|
309
|
-
return /^[UBPT][A-Z0-9]{10}$/i.test(t) || /^user:/i.test(t);
|
|
310
|
-
},
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
security: {
|
|
314
|
-
resolveDmPolicy({ accountId }) {
|
|
315
|
-
const basePath = accountId && accountId !== 'default'
|
|
316
|
-
? `channels.deskfree.accounts.${accountId}.dm.`
|
|
317
|
-
: 'channels.deskfree.dm.';
|
|
318
|
-
return {
|
|
319
|
-
policy: 'open',
|
|
320
|
-
allowFrom: ['*'],
|
|
321
|
-
allowFromPath: basePath,
|
|
322
|
-
approveHint: 'DeskFree uses bot token auth — no pairing needed.',
|
|
323
|
-
};
|
|
324
|
-
},
|
|
325
|
-
},
|
|
326
|
-
onboarding: {
|
|
327
|
-
channel: 'deskfree',
|
|
328
|
-
async getStatus(ctx) {
|
|
329
|
-
const ch = getChannelConfig(ctx.cfg);
|
|
330
|
-
const hasBotToken = Boolean(ch?.botToken);
|
|
331
|
-
const hasApiUrl = Boolean(ch?.apiUrl);
|
|
332
|
-
const hasUserId = Boolean(ch?.userId);
|
|
333
|
-
const configured = hasBotToken && hasApiUrl && hasUserId;
|
|
334
|
-
const statusLines = [];
|
|
335
|
-
if (configured) {
|
|
336
|
-
statusLines.push('Bot token: configured');
|
|
337
|
-
statusLines.push(`API URL: ${ch.apiUrl}`);
|
|
338
|
-
if (ch.wsUrl)
|
|
339
|
-
statusLines.push(`WS URL: ${ch.wsUrl}`);
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
statusLines.push('Not configured');
|
|
343
|
-
}
|
|
344
|
-
return {
|
|
345
|
-
channel: 'deskfree',
|
|
346
|
-
configured,
|
|
347
|
-
statusLines,
|
|
348
|
-
selectionHint: CHANNEL_HINTS.onboardingSelection,
|
|
349
|
-
quickstartScore: configured ? 0 : 50,
|
|
350
|
-
};
|
|
351
|
-
},
|
|
352
|
-
async configure(ctx) {
|
|
353
|
-
const ch = getChannelConfig(ctx.cfg);
|
|
354
|
-
const accountId = ctx.accountOverrides.accountId ?? 'default';
|
|
355
|
-
const botToken = await ctx.prompter.text({
|
|
356
|
-
message: 'Bot token',
|
|
357
|
-
initialValue: ch?.botToken ?? '',
|
|
358
|
-
placeholder: 'bot_xxxxxxxxxxxxxxxx',
|
|
359
|
-
validate: (v) => {
|
|
360
|
-
if (!v)
|
|
361
|
-
return 'Bot token is required';
|
|
362
|
-
if (!v.startsWith('bot_'))
|
|
363
|
-
return 'Must start with "bot_"';
|
|
364
|
-
if (v.length < 10)
|
|
365
|
-
return 'Bot token appears to be too short';
|
|
366
|
-
return undefined;
|
|
367
|
-
},
|
|
368
|
-
});
|
|
369
|
-
const apiUrl = await ctx.prompter.text({
|
|
370
|
-
message: 'API URL',
|
|
371
|
-
initialValue: ch?.apiUrl ?? '',
|
|
372
|
-
placeholder: 'https://app.deskfree.ai/v1/bot',
|
|
373
|
-
validate: (v) => {
|
|
374
|
-
if (!v)
|
|
375
|
-
return 'API URL is required';
|
|
376
|
-
try {
|
|
377
|
-
const url = new URL(v);
|
|
378
|
-
if (url.protocol !== 'https:')
|
|
379
|
-
return 'Must use HTTPS protocol for security';
|
|
380
|
-
return undefined;
|
|
381
|
-
}
|
|
382
|
-
catch {
|
|
383
|
-
return 'Must be a valid HTTPS URL';
|
|
384
|
-
}
|
|
385
|
-
},
|
|
386
|
-
});
|
|
387
|
-
const wsUrl = await ctx.prompter.text({
|
|
388
|
-
message: 'WebSocket URL',
|
|
389
|
-
initialValue: ch?.wsUrl ?? '',
|
|
390
|
-
placeholder: 'wss://ws.deskfree.ai',
|
|
391
|
-
validate: (v) => {
|
|
392
|
-
if (!v)
|
|
393
|
-
return 'WebSocket URL is required';
|
|
394
|
-
try {
|
|
395
|
-
const url = new URL(v);
|
|
396
|
-
if (!['ws:', 'wss:'].includes(url.protocol)) {
|
|
397
|
-
return 'Must use ws:// or wss:// protocol';
|
|
398
|
-
}
|
|
399
|
-
return undefined;
|
|
400
|
-
}
|
|
401
|
-
catch {
|
|
402
|
-
return 'Must be a valid WebSocket URL';
|
|
403
|
-
}
|
|
404
|
-
},
|
|
405
|
-
});
|
|
406
|
-
const userId = await ctx.prompter.text({
|
|
407
|
-
message: 'Your DeskFree User ID (shown in install instructions)',
|
|
408
|
-
initialValue: ch?.userId ?? '',
|
|
409
|
-
placeholder: 'U9QF3C6X1A',
|
|
410
|
-
validate: (v) => {
|
|
411
|
-
if (!v)
|
|
412
|
-
return 'User ID is required';
|
|
413
|
-
if (!/^[UBPT][A-Z0-9]{10}$/i.test(v)) {
|
|
414
|
-
return 'Must be a valid DeskFree ID (e.g. U9QF3C6X1A)';
|
|
415
|
-
}
|
|
416
|
-
return undefined;
|
|
417
|
-
},
|
|
418
|
-
});
|
|
419
|
-
const updatedCfg = deskFreePlugin.setup.applyAccountConfig({
|
|
420
|
-
cfg: ctx.cfg,
|
|
421
|
-
accountId,
|
|
422
|
-
input: { botToken, apiUrl, wsUrl, userId },
|
|
423
|
-
});
|
|
424
|
-
await ctx.prompter.note('DeskFree channel configured.', 'Done');
|
|
425
|
-
return { cfg: updatedCfg, accountId };
|
|
426
|
-
},
|
|
427
|
-
disable(cfg) {
|
|
428
|
-
const config = JSON.parse(JSON.stringify(cfg));
|
|
429
|
-
const channels = (config.channels ?? {});
|
|
430
|
-
const deskfree = (channels.deskfree ?? {});
|
|
431
|
-
deskfree.enabled = false;
|
|
432
|
-
channels.deskfree = deskfree;
|
|
433
|
-
config.channels = channels;
|
|
434
|
-
return config;
|
|
435
|
-
},
|
|
436
|
-
},
|
|
437
|
-
status: {
|
|
438
|
-
async probeAccount(params) {
|
|
439
|
-
const isConfigured = Boolean(params.account.botToken && params.account.apiUrl);
|
|
440
|
-
if (!isConfigured) {
|
|
441
|
-
return { ok: false, error: STATUS_MESSAGES.probeNotConfigured };
|
|
442
|
-
}
|
|
443
|
-
const client = new DeskFreeClient(params.account.botToken, params.account.apiUrl);
|
|
444
|
-
return client.probe(params.timeoutMs);
|
|
445
|
-
},
|
|
446
|
-
buildAccountSnapshot(params) {
|
|
447
|
-
const isConfigured = Boolean(params.account.botToken && params.account.apiUrl);
|
|
448
|
-
return {
|
|
449
|
-
accountId: params.account.accountId,
|
|
450
|
-
enabled: params.account.enabled,
|
|
451
|
-
configured: isConfigured,
|
|
452
|
-
running: params.runtime?.running,
|
|
453
|
-
lastStartAt: params.runtime?.lastStartAt,
|
|
454
|
-
lastStopAt: params.runtime?.lastStopAt,
|
|
455
|
-
lastError: params.runtime?.lastError,
|
|
456
|
-
probe: params.probe,
|
|
457
|
-
};
|
|
458
|
-
},
|
|
459
|
-
collectStatusIssues(accounts) {
|
|
460
|
-
const issues = [];
|
|
461
|
-
for (const snap of accounts) {
|
|
462
|
-
const id = snap.accountId ?? 'unknown';
|
|
463
|
-
if (!snap.configured) {
|
|
464
|
-
issues.push({
|
|
465
|
-
channel: 'deskfree',
|
|
466
|
-
accountId: id,
|
|
467
|
-
kind: 'config',
|
|
468
|
-
message: STATUS_MESSAGES.notConfigured.message,
|
|
469
|
-
fix: STATUS_MESSAGES.notConfigured.fix,
|
|
470
|
-
});
|
|
471
|
-
continue;
|
|
472
|
-
}
|
|
473
|
-
if (!snap.enabled) {
|
|
474
|
-
issues.push({
|
|
475
|
-
channel: 'deskfree',
|
|
476
|
-
accountId: id,
|
|
477
|
-
kind: 'config',
|
|
478
|
-
message: STATUS_MESSAGES.disabled.message,
|
|
479
|
-
fix: STATUS_MESSAGES.disabled.fix,
|
|
480
|
-
});
|
|
481
|
-
continue;
|
|
482
|
-
}
|
|
483
|
-
if (!snap.running) {
|
|
484
|
-
issues.push({
|
|
485
|
-
channel: 'deskfree',
|
|
486
|
-
accountId: id,
|
|
487
|
-
kind: 'runtime',
|
|
488
|
-
message: STATUS_MESSAGES.notRunning.message,
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
if (snap.probe && !snap.probe.ok) {
|
|
492
|
-
issues.push({
|
|
493
|
-
channel: 'deskfree',
|
|
494
|
-
accountId: id,
|
|
495
|
-
kind: 'auth',
|
|
496
|
-
message: `Probe failed: ${snap.probe.error ?? 'unknown error'}`,
|
|
497
|
-
fix: STATUS_MESSAGES.probeFailed.fix,
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
return issues;
|
|
502
|
-
},
|
|
503
|
-
},
|
|
504
|
-
};
|
|
505
|
-
//# sourceMappingURL=channel.js.map
|