@celljs/ta-protocol 4.16.0 → 4.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/esm/common/app-protocol.d.ts +115 -0
  2. package/esm/common/app-protocol.js +199 -0
  3. package/esm/common/delegate-protocol.d.ts +30 -0
  4. package/esm/common/delegate-protocol.js +52 -0
  5. package/esm/common/deployment-protocol.d.ts +59 -0
  6. package/esm/common/deployment-protocol.js +135 -0
  7. package/esm/common/error-protocol.d.ts +42 -0
  8. package/esm/common/error-protocol.js +45 -0
  9. package/esm/common/event-protocol.d.ts +63 -0
  10. package/esm/common/event-protocol.js +2 -0
  11. package/esm/common/gateway-protocol.d.ts +29 -0
  12. package/esm/common/index.d.ts +9 -0
  13. package/esm/common/index.js +9 -0
  14. package/esm/common/message-protocol.d.ts +95 -0
  15. package/esm/common/message-protocol.js +237 -0
  16. package/esm/common/page-protocol.d.ts +56 -0
  17. package/esm/common/page-protocol.js +12 -0
  18. package/esm/common/path-map.d.ts +24 -0
  19. package/esm/common/path-map.js +127 -0
  20. package/esm/common/presence-protocol.js +1 -1
  21. package/esm/common/redactor.d.ts +12 -0
  22. package/esm/common/redactor.js +49 -11
  23. package/esm/common/relay-protocol.d.ts +20 -0
  24. package/esm/common/room-protocol.d.ts +7 -1
  25. package/esm/common/ta-extension-host.d.ts +31 -1
  26. package/esm/common/ta-extension-host.js +2 -0
  27. package/esm/common/ta-protocol.d.ts +50 -175
  28. package/esm/common/ta-protocol.js +0 -234
  29. package/esm/common/voice-protocol.d.ts +139 -0
  30. package/esm/common/voice-protocol.js +3 -0
  31. package/lib/common/app-protocol.d.ts +116 -0
  32. package/lib/common/app-protocol.js +202 -0
  33. package/lib/common/delegate-protocol.d.ts +31 -0
  34. package/lib/common/delegate-protocol.js +55 -0
  35. package/lib/common/deployment-protocol.d.ts +60 -0
  36. package/lib/common/deployment-protocol.js +139 -0
  37. package/lib/common/error-protocol.d.ts +43 -0
  38. package/lib/common/error-protocol.js +48 -0
  39. package/lib/common/event-protocol.d.ts +64 -0
  40. package/lib/common/event-protocol.js +3 -0
  41. package/lib/common/gateway-protocol.d.ts +29 -0
  42. package/lib/common/index.d.ts +9 -0
  43. package/lib/common/index.js +9 -0
  44. package/lib/common/message-protocol.d.ts +96 -0
  45. package/lib/common/message-protocol.js +240 -0
  46. package/lib/common/page-protocol.d.ts +57 -0
  47. package/lib/common/page-protocol.js +15 -0
  48. package/lib/common/path-map.d.ts +25 -0
  49. package/lib/common/path-map.js +130 -0
  50. package/lib/common/presence-protocol.js +7 -7
  51. package/lib/common/redactor.d.ts +12 -0
  52. package/lib/common/redactor.js +49 -11
  53. package/lib/common/relay-protocol.d.ts +20 -0
  54. package/lib/common/room-protocol.d.ts +7 -1
  55. package/lib/common/ta-extension-host.d.ts +31 -1
  56. package/lib/common/ta-extension-host.js +3 -1
  57. package/lib/common/ta-protocol.d.ts +50 -175
  58. package/lib/common/ta-protocol.js +1 -235
  59. package/lib/common/voice-protocol.d.ts +140 -0
  60. package/lib/common/voice-protocol.js +6 -0
  61. package/package.json +1 -1
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TA_RPC_ERROR_CODE = exports.TaErrorUtil = exports.TaErrorCode = void 0;
4
+ /** The stable `code` of each failure of a {@link TaServer} call. */
5
+ exports.TaErrorCode = {
6
+ SESSION_NOT_FOUND: 'CELL_TA_SESSION_NOT_FOUND',
7
+ SESSION_LOCKED: 'CELL_TA_SESSION_LOCKED',
8
+ TOO_MANY_SESSIONS: 'CELL_TA_TOO_MANY_SESSIONS',
9
+ MESSAGE_CONFLICT: 'CELL_TA_MESSAGE_CONFLICT',
10
+ MODEL_NOT_FOUND: 'CELL_TA_MODEL_NOT_FOUND',
11
+ INVALID_ARGUMENT: 'CELL_TA_INVALID_ARGUMENT',
12
+ COMMAND_FAILED: 'CELL_TA_COMMAND_FAILED',
13
+ /** Compacting found nothing to compact: the conversation is still short. */
14
+ NOTHING_TO_COMPACT: 'CELL_TA_NOTHING_TO_COMPACT',
15
+ /** Compacting found nothing to compact: nothing came after the last compaction. */
16
+ ALREADY_COMPACTED: 'CELL_TA_ALREADY_COMPACTED',
17
+ /** The session is answering or compacting, which has to end first. */
18
+ SESSION_BUSY: 'CELL_TA_SESSION_BUSY',
19
+ /** Stopped before it ended, by the user (abort) or an extension: nothing to report. */
20
+ CANCELLED: 'CELL_TA_CANCELLED',
21
+ /** No provider of models is signed in for the model, or there is no model: sign in (TaAuthServer) first. */
22
+ NOT_SIGNED_IN: 'CELL_TA_NOT_SIGNED_IN',
23
+ /** Behind a gateway (`ta gateway`): the environment of the tenant did not start; TaGatewayServer changes or restarts it. */
24
+ ENVIRONMENT_FAILED: 'CELL_TA_ENVIRONMENT_FAILED',
25
+ /** Behind a gateway: more messages a minute than one may send; try again in a moment. */
26
+ RATE_LIMITED: 'CELL_TA_RATE_LIMITED',
27
+ /** One let in by the user (docs/design/ta-team.md) may not do this: `data` says the action it needs (TaForbiddenData). */
28
+ FORBIDDEN: 'CELL_TA_FORBIDDEN',
29
+ /** As many runs of people let in go as the owner lets at once (docs/design/ta-team.md 9): try again once one ended. */
30
+ LIMIT: 'CELL_TA_LIMIT',
31
+ /** Raised by the client, not the server: the call could not reach ta serve, or its answer was lost with the connection. */
32
+ CONNECTION_LOST: 'CELL_TA_CONNECTION_LOST',
33
+ };
34
+ var TaErrorUtil;
35
+ (function (TaErrorUtil) {
36
+ /** The {@link TaErrorCode} of a failure: `code` of the client's error, `data.code` of the server's own, called in its process. */
37
+ function code(error) {
38
+ var _a;
39
+ var _b;
40
+ const failure = error;
41
+ const code = (_b = failure === null || failure === void 0 ? void 0 : failure.code) !== null && _b !== void 0 ? _b : (_a = failure === null || failure === void 0 ? void 0 : failure.data) === null || _a === void 0 ? void 0 : _a.code;
42
+ return typeof code === 'string' ? code : undefined;
43
+ }
44
+ TaErrorUtil.code = code;
45
+ })(TaErrorUtil || (exports.TaErrorUtil = TaErrorUtil = {}));
46
+ /** The JSON-RPC error code of every failure of a {@link TaServer} call; `data.code` tells them apart. */
47
+ exports.TA_RPC_ERROR_CODE = -32050;
48
+ //# sourceMappingURL=error-protocol.js.map
@@ -0,0 +1,64 @@
1
+ import type { JsonAgentSessionEvent, RpcExtensionUIRequest } from './pi-types';
2
+ import type { TaSessionInfo } from './ta-protocol';
3
+ /** An extension's dialog was answered by another client, or expired. */
4
+ export interface TaUiRequestResolved {
5
+ type: 'ui_request_resolved';
6
+ id: string;
7
+ }
8
+ /** An extension threw while handling an event. */
9
+ export interface TaExtensionError {
10
+ type: 'extension_error';
11
+ extensionPath: string;
12
+ event: string;
13
+ error: string;
14
+ }
15
+ /** The open session now shows another conversation (`newSession`, `switchSession`, `fork`, `clone`, `navigateTree`): read it again. */
16
+ export interface TaSessionReplaced {
17
+ type: 'session_replaced';
18
+ info: TaSessionInfo;
19
+ }
20
+ /**
21
+ * The session loaded its extensions, skills, prompts and themes again (`reload`, or an extension's
22
+ * `ctx.reload()`): its commands may have changed, read them again (`getCommands`).
23
+ */
24
+ export interface TaSessionReloaded {
25
+ type: 'session_reloaded';
26
+ }
27
+ /** The session was closed; no more events come. */
28
+ export interface TaSessionClosed {
29
+ type: 'session_closed';
30
+ }
31
+ /**
32
+ * What the agent is doing while it works, from an extension (pi's `setWorkingMessage`), as starting the
33
+ * program of an external agent; none: the client's own words again.
34
+ */
35
+ export interface TaWorkingMessage {
36
+ type: 'working_message';
37
+ message?: string;
38
+ }
39
+ /**
40
+ * The model called a tool of `clientTools`: a client that runs it takes it with `claimClientTool`, so
41
+ * that one client runs it, however many are attached, and answers with `respondClientTool`. When that
42
+ * client leaves the session before it answers, the request comes again with the same id, for another.
43
+ * `client_tool_resolved` tells the others it was answered.
44
+ */
45
+ export interface TaClientToolRequest {
46
+ type: 'client_tool_request';
47
+ /** The id of the tool call. */
48
+ id: string;
49
+ toolName: string;
50
+ input: unknown;
51
+ }
52
+ /** A call of a client tool was answered, or ended because the run was aborted or the session closed. */
53
+ export interface TaClientToolResolved {
54
+ type: 'client_tool_resolved';
55
+ id: string;
56
+ }
57
+ export type TaEvent = JsonAgentSessionEvent | RpcExtensionUIRequest | TaUiRequestResolved | TaExtensionError | TaClientToolRequest | TaClientToolResolved | TaSessionReplaced | TaSessionReloaded | TaSessionClosed | TaWorkingMessage;
58
+ export interface TaEventEnvelope {
59
+ sessionId: string;
60
+ /** Increases by one per event of the session. */
61
+ seq: number;
62
+ event: TaEvent;
63
+ }
64
+ //# sourceMappingURL=event-protocol.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=event-protocol.js.map
@@ -28,6 +28,15 @@ export interface TaGatewayLimits {
28
28
  /** Whether they may run their Ta in a Ta service of their own. */
29
29
  own?: boolean | null;
30
30
  }
31
+ /** A connection of a sandbox the proxy of the gateway refused, the latest of its kind: `count` of them lately. */
32
+ export interface TaEgressRefusal {
33
+ /** `host`, or `host:port` for a port other than 80 and 443. */
34
+ host: string;
35
+ /** Not among the hosts of the policy, a port it does not let out, or a private network or the gateway's machine. */
36
+ reason: 'host' | 'port' | 'network';
37
+ at: number;
38
+ count: number;
39
+ }
31
40
  /** Why one's Ta does not start: suspended by an administrator, or this month's free minutes used up. */
32
41
  export type TaQuotaBlock = 'suspended' | 'minutes';
33
42
  /** What one used of what one may, this month (of UTC), as one sees it and administrators do. */
@@ -55,6 +64,11 @@ export interface TaQuotaState {
55
64
  promptsPerMinute?: number;
56
65
  connections?: number;
57
66
  blocked?: TaQuotaBlock;
67
+ /** When the sandboxes go out through the gateway: the bytes moved this month, and the latest connections refused. */
68
+ egress?: {
69
+ bytes: number;
70
+ refused: TaEgressRefusal[];
71
+ };
58
72
  }
59
73
  /** One hour of what agents took: tokens and dollars. */
60
74
  export interface TaUsagePoint {
@@ -99,6 +113,18 @@ export interface TaGatewayAuditEntry {
99
113
  target?: string;
100
114
  detail?: string;
101
115
  }
116
+ /**
117
+ * The way out of the sandboxes: the proxy of the gateway, by which each sandbox goes out with credentials of its
118
+ * own epoch (those of a sandbox made again since stop working).
119
+ */
120
+ export interface TaGatewayEgress {
121
+ /** Whether the sandboxes go out through the gateway (`egress` of sandboxes.json, with the firewall of the machine). */
122
+ enabled: boolean;
123
+ /** The hosts members' sandboxes may reach, set by owners; none: any public host. Owners are not held to them. */
124
+ hosts: string[];
125
+ /** Private networks the sandboxes may reach too (`egress.networks` of sandboxes.json); never the gateway's machine. */
126
+ networks: string[];
127
+ }
102
128
  /** The defaults of the gateway and who manages it. */
103
129
  export interface TaGatewayPolicy {
104
130
  defaults: TaGatewayLimits;
@@ -108,6 +134,7 @@ export interface TaGatewayPolicy {
108
134
  role: 'owner' | 'admin';
109
135
  }[];
110
136
  idleMinutes: number;
137
+ egress: TaGatewayEgress;
111
138
  }
112
139
  /**
113
140
  * Where the Ta of a tenant runs: a sandbox of the gateway's provider (a container, a machine), or a Ta service
@@ -331,6 +358,8 @@ export interface TaGatewayServer {
331
358
  grantMinutes(tenantId: string, minutes: number): Promise<void>;
332
359
  /** For administrators: a suspended account's Ta stops and does not start until it is let go again. */
333
360
  setSuspended(tenantId: string, suspended: boolean): Promise<void>;
361
+ /** For owners: the hosts members' sandboxes may reach through the proxy of the gateway; none: any public host. */
362
+ setEgressHosts(hosts: string[]): Promise<TaGatewayPolicy>;
334
363
  /** For owners: makes an account that signed in an admin, or a member again. Owners stay owners. */
335
364
  setRole(account: string, role: 'admin' | 'member'): Promise<TaGatewayPolicy>;
336
365
  /** For administrators: what administrators did lately, newest first, `limit` at most (100 by default). */
@@ -1,9 +1,17 @@
1
1
  export * from './access-protocol';
2
+ export * from './app-protocol';
2
3
  export * from './auth-protocol';
4
+ export * from './delegate-protocol';
5
+ export * from './deployment-protocol';
6
+ export * from './error-protocol';
7
+ export * from './event-protocol';
3
8
  export * from './gateway-protocol';
4
9
  export * from './language';
5
10
  export * from './location';
11
+ export * from './message-protocol';
6
12
  export * from './package-protocol';
13
+ export * from './page-protocol';
14
+ export * from './path-map';
7
15
  export * from './pi-types';
8
16
  export * from './presence-protocol';
9
17
  export * from './relay-protocol';
@@ -14,5 +22,6 @@ export * from './ta-extension-host';
14
22
  export * from './ta-protocol';
15
23
  export * from './team-protocol';
16
24
  export * from './usage-protocol';
25
+ export * from './voice-protocol';
17
26
  export * from './workspace-protocol';
18
27
  //# sourceMappingURL=index.d.ts.map
@@ -15,11 +15,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./access-protocol"), exports);
18
+ __exportStar(require("./app-protocol"), exports);
18
19
  __exportStar(require("./auth-protocol"), exports);
20
+ __exportStar(require("./delegate-protocol"), exports);
21
+ __exportStar(require("./deployment-protocol"), exports);
22
+ __exportStar(require("./error-protocol"), exports);
23
+ __exportStar(require("./event-protocol"), exports);
19
24
  __exportStar(require("./gateway-protocol"), exports);
20
25
  __exportStar(require("./language"), exports);
21
26
  __exportStar(require("./location"), exports);
27
+ __exportStar(require("./message-protocol"), exports);
22
28
  __exportStar(require("./package-protocol"), exports);
29
+ __exportStar(require("./page-protocol"), exports);
30
+ __exportStar(require("./path-map"), exports);
23
31
  __exportStar(require("./pi-types"), exports);
24
32
  __exportStar(require("./presence-protocol"), exports);
25
33
  __exportStar(require("./relay-protocol"), exports);
@@ -30,5 +38,6 @@ __exportStar(require("./ta-extension-host"), exports);
30
38
  __exportStar(require("./ta-protocol"), exports);
31
39
  __exportStar(require("./team-protocol"), exports);
32
40
  __exportStar(require("./usage-protocol"), exports);
41
+ __exportStar(require("./voice-protocol"), exports);
33
42
  __exportStar(require("./workspace-protocol"), exports);
34
43
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,96 @@
1
+ /**
2
+ * A message of the user may start with a `<context>` block: what the model reads besides the message
3
+ * (where it is said, who is there, what was said before), which a client leaves out when it shows it.
4
+ */
5
+ export declare namespace TaMessageContext {
6
+ function wrap(context: string, message: string): string;
7
+ /** The message without its context: what the user sees of it. */
8
+ function strip(message: string): string;
9
+ /** The context of the message, without its tags; undefined without one. */
10
+ function read(message: string): string | undefined;
11
+ }
12
+ /** Where a message of the user came from, when not from what they typed: see {@link TaMessageSource}. */
13
+ export interface TaMessageFrom {
14
+ /** The name of the package that sent it, or TaMessageSource.DOUBLE. */
15
+ from: string;
16
+ /** What the package says of it besides, in a few words (the channel and who spoke in it). */
17
+ detail?: string;
18
+ }
19
+ /**
20
+ * A message a package sends as the user (a choice in a card, a scheduled task, a channel) says so in the last line
21
+ * of its `<context>` block, `[ta:from <name> <detail>]`: a page shows where it came from, the model reads it too,
22
+ * and a page older than it leaves it out with the rest of the context. A command (`/compact`, `!ls`) is not marked.
23
+ */
24
+ export declare namespace TaMessageSource {
25
+ /** The double of the web page: the tasks it hands out, what it tells them on the way. */
26
+ const DOUBLE = "ta:double";
27
+ /** `message` as sent by `from`; as it was when it is a command or says where it came from already. */
28
+ function mark(message: string, from: string, detail?: string): string;
29
+ function of(message: string): TaMessageFrom | undefined;
30
+ }
31
+ /**
32
+ * pi adds a line to the text of a message of the user for each image it took, for the model's sake: how big
33
+ * the image was before it made it smaller, and what it was converted from. Clients leave them out.
34
+ */
35
+ export declare namespace TaImageNote {
36
+ /** The text without the notes of its images: what the user sees of it. */
37
+ function strip(text: string): string;
38
+ }
39
+ /** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
40
+ export declare namespace TaImageSize {
41
+ function of(base64: string): {
42
+ width: number;
43
+ height: number;
44
+ } | undefined;
45
+ }
46
+ /**
47
+ * An external agent that compacts its own context says the summary it goes on from as text, in tags
48
+ * (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
49
+ */
50
+ export declare namespace TaAgentSummary {
51
+ /** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
52
+ function read(text: string): string | undefined;
53
+ /** The text without the summary it starts with. */
54
+ function strip(text: string): string;
55
+ }
56
+ /** A skill the user ran with `/skill:name`, as pi puts it in the message: the skill's file, then what the user wrote. */
57
+ export interface TaSkillUse {
58
+ name: string;
59
+ /** The path of its SKILL.md. */
60
+ location: string;
61
+ /** What pi read of it, for the model. */
62
+ content: string;
63
+ /** What the user wrote after `/skill:name`. */
64
+ message?: string;
65
+ }
66
+ /** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
67
+ export declare namespace TaSkillUse {
68
+ function parse(message: string): TaSkillUse | undefined;
69
+ /** What the user typed: `/skill:name` and what follows. */
70
+ function command(use: TaSkillUse): string;
71
+ }
72
+ /** What a note of the double's tasks is about: how one ended, that the user handed it one, that one has another id now. */
73
+ export type TaTaskNoteKind = 'update' | 'adopted' | 'renamed';
74
+ /** A note of the double's tasks, as {@link TaTaskNote.write} puts it and {@link TaTaskNote.parse} reads it. */
75
+ export interface TaTaskNote {
76
+ kind: TaTaskNoteKind;
77
+ id: string;
78
+ title: string;
79
+ /** How the task stands: running, done, failed, stopped; none in a note of a new id. */
80
+ status?: string;
81
+ /** The id it had, in a note of a new id. */
82
+ was?: string;
83
+ /** What the note says, for the double. */
84
+ body: string;
85
+ }
86
+ /**
87
+ * The double hears of its tasks in messages of the user (`<task_update id="t1" title="…" status="done">…</task_update>`
88
+ * and the like): notes, not what the user said, which a client shows as the task they are about, and a list of
89
+ * conversations says by the task's title.
90
+ */
91
+ export declare namespace TaTaskNote {
92
+ function write(note: TaTaskNote): string;
93
+ /** The note `text` is, all of it; undefined for anything else. */
94
+ function parse(text: string): TaTaskNote | undefined;
95
+ }
96
+ //# sourceMappingURL=message-protocol.d.ts.map
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaTaskNote = exports.TaSkillUse = exports.TaAgentSummary = exports.TaImageSize = exports.TaImageNote = exports.TaMessageSource = exports.TaMessageContext = void 0;
4
+ /**
5
+ * A message of the user may start with a `<context>` block: what the model reads besides the message
6
+ * (where it is said, who is there, what was said before), which a client leaves out when it shows it.
7
+ */
8
+ var TaMessageContext;
9
+ (function (TaMessageContext) {
10
+ const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
11
+ function wrap(context, message) {
12
+ return `<context>\n${context}\n</context>\n${message}`;
13
+ }
14
+ TaMessageContext.wrap = wrap;
15
+ /** The message without its context: what the user sees of it. */
16
+ function strip(message) {
17
+ return message.replace(BLOCK, '');
18
+ }
19
+ TaMessageContext.strip = strip;
20
+ /** The context of the message, without its tags; undefined without one. */
21
+ function read(message) {
22
+ var _a;
23
+ const block = (_a = BLOCK.exec(message)) === null || _a === void 0 ? void 0 : _a[0];
24
+ return block === null || block === void 0 ? void 0 : block.replace(/^<context>\n?/, '').replace(/\n?<\/context>\n?$/, '');
25
+ }
26
+ TaMessageContext.read = read;
27
+ })(TaMessageContext || (exports.TaMessageContext = TaMessageContext = {}));
28
+ /**
29
+ * A message a package sends as the user (a choice in a card, a scheduled task, a channel) says so in the last line
30
+ * of its `<context>` block, `[ta:from <name> <detail>]`: a page shows where it came from, the model reads it too,
31
+ * and a page older than it leaves it out with the rest of the context. A command (`/compact`, `!ls`) is not marked.
32
+ */
33
+ var TaMessageSource;
34
+ (function (TaMessageSource) {
35
+ /** The double of the web page: the tasks it hands out, what it tells them on the way. */
36
+ TaMessageSource.DOUBLE = 'ta:double';
37
+ const LINE = /^\[ta:from ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
38
+ /** `message` as sent by `from`; as it was when it is a command or says where it came from already. */
39
+ function mark(message, from, detail) {
40
+ if (/^[/!]/.test(message) || of(message)) {
41
+ return message;
42
+ }
43
+ const line = `[ta:from ${from}${detail ? ` ${detail.replace(/[\]\n]/g, ' ')}` : ''}]`;
44
+ const context = TaMessageContext.read(message);
45
+ return TaMessageContext.wrap(context === undefined ? line : `${context}\n${line}`, TaMessageContext.strip(message));
46
+ }
47
+ TaMessageSource.mark = mark;
48
+ function of(message) {
49
+ const context = TaMessageContext.read(message);
50
+ const match = context === undefined ? null : LINE.exec(context);
51
+ return match ? { from: match[1], ...(match[2] ? { detail: match[2].trim() } : {}) } : undefined;
52
+ }
53
+ TaMessageSource.of = of;
54
+ })(TaMessageSource || (exports.TaMessageSource = TaMessageSource = {}));
55
+ /**
56
+ * pi adds a line to the text of a message of the user for each image it took, for the model's sake: how big
57
+ * the image was before it made it smaller, and what it was converted from. Clients leave them out.
58
+ */
59
+ var TaImageNote;
60
+ (function (TaImageNote) {
61
+ const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
62
+ /** The text without the notes of its images: what the user sees of it. */
63
+ function strip(text) {
64
+ const lines = text.split('\n');
65
+ const kept = lines.filter(line => !NOTE.test(line.trim()));
66
+ if (kept.length === lines.length) {
67
+ return text;
68
+ }
69
+ return kept.join('\n').replace(/\n+$/, '').replace(/^\n+/, '');
70
+ }
71
+ TaImageNote.strip = strip;
72
+ })(TaImageNote || (exports.TaImageNote = TaImageNote = {}));
73
+ /** The width and height of an image, read from the start of its bytes (PNG, JPEG, GIF, WebP); undefined for another kind. */
74
+ var TaImageSize;
75
+ (function (TaImageSize) {
76
+ /** How much of a JPEG is read for its size: the frame header follows what the camera wrote, a thumbnail too. */
77
+ const JPEG_BYTES = 256 * 1024;
78
+ function of(base64) {
79
+ var _a, _b, _c;
80
+ let bytes;
81
+ try {
82
+ // Whole groups of four characters only.
83
+ const binary = atob(base64.slice(0, Math.ceil((JPEG_BYTES * 4) / 3 / 4) * 4));
84
+ bytes = Uint8Array.from(binary, char => char.charCodeAt(0));
85
+ }
86
+ catch (_d) {
87
+ return undefined;
88
+ }
89
+ const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== void 0 ? _a : gif(bytes)) !== null && _b !== void 0 ? _b : webp(bytes)) !== null && _c !== void 0 ? _c : jpeg(bytes);
90
+ return size && size.width > 0 && size.height > 0 ? size : undefined;
91
+ }
92
+ TaImageSize.of = of;
93
+ function u16be(bytes, at) {
94
+ return (bytes[at] << 8) | bytes[at + 1];
95
+ }
96
+ function u16le(bytes, at) {
97
+ return bytes[at] | (bytes[at + 1] << 8);
98
+ }
99
+ function u24le(bytes, at) {
100
+ return bytes[at] | (bytes[at + 1] << 8) | (bytes[at + 2] << 16);
101
+ }
102
+ function u32be(bytes, at) {
103
+ return ((bytes[at] << 24) | (bytes[at + 1] << 16) | (bytes[at + 2] << 8) | bytes[at + 3]) >>> 0;
104
+ }
105
+ function text(bytes, at, length) {
106
+ return String.fromCharCode(...bytes.subarray(at, at + length));
107
+ }
108
+ function png(bytes) {
109
+ return bytes.length >= 24 && bytes[0] === 0x89 && text(bytes, 1, 3) === 'PNG' ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
110
+ }
111
+ function gif(bytes) {
112
+ return bytes.length >= 10 && text(bytes, 0, 3) === 'GIF' ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
113
+ }
114
+ function webp(bytes) {
115
+ if (bytes.length < 30 || text(bytes, 0, 4) !== 'RIFF' || text(bytes, 8, 4) !== 'WEBP') {
116
+ return undefined;
117
+ }
118
+ switch (text(bytes, 12, 4)) {
119
+ case 'VP8 ':
120
+ return { width: u16le(bytes, 26) & 0x3fff, height: u16le(bytes, 28) & 0x3fff };
121
+ case 'VP8L': {
122
+ const bits = bytes[21] | (bytes[22] << 8) | (bytes[23] << 16) | (bytes[24] << 24);
123
+ return { width: (bits & 0x3fff) + 1, height: ((bits >> 14) & 0x3fff) + 1 };
124
+ }
125
+ case 'VP8X':
126
+ return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
127
+ default:
128
+ return undefined;
129
+ }
130
+ }
131
+ function jpeg(bytes) {
132
+ if (bytes[0] !== 0xff || bytes[1] !== 0xd8) {
133
+ return undefined;
134
+ }
135
+ let at = 2;
136
+ while (at + 9 < bytes.length) {
137
+ if (bytes[at] !== 0xff) {
138
+ return undefined;
139
+ }
140
+ const marker = bytes[at + 1];
141
+ // A start of frame (not DHT, JPG or DAC, which share the range) says the size.
142
+ if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
143
+ return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
144
+ }
145
+ at += 2 + u16be(bytes, at + 2);
146
+ }
147
+ return undefined;
148
+ }
149
+ })(TaImageSize || (exports.TaImageSize = TaImageSize = {}));
150
+ /**
151
+ * An external agent that compacts its own context says the summary it goes on from as text, in tags
152
+ * (`<conversation_history_summary><summary>…`). Clients show it folded, not as what the agent said.
153
+ */
154
+ var TaAgentSummary;
155
+ (function (TaAgentSummary) {
156
+ const START = /^\s*<conversation_history_summary>/;
157
+ const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
158
+ /** The summary `text` is, without its tags (and the start of a closing tag while it streams); else undefined. */
159
+ function read(text) {
160
+ if (!START.test(text)) {
161
+ return undefined;
162
+ }
163
+ return text
164
+ .replace(/<\/?(?:conversation_history_summary|summary)>/g, '')
165
+ .replace(/<\/?\w*$/, '')
166
+ .trim();
167
+ }
168
+ TaAgentSummary.read = read;
169
+ /** The text without the summary it starts with. */
170
+ function strip(text) {
171
+ return text.replace(BLOCK, '');
172
+ }
173
+ TaAgentSummary.strip = strip;
174
+ })(TaAgentSummary || (exports.TaAgentSummary = TaAgentSummary = {}));
175
+ /** The `<skill>` block pi expands `/skill:name` into (its `parseSkillBlock`), which a client shows as the skill it is. */
176
+ var TaSkillUse;
177
+ (function (TaSkillUse) {
178
+ const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
179
+ function parse(message) {
180
+ var _a;
181
+ const match = BLOCK.exec(message);
182
+ if (!match) {
183
+ return undefined;
184
+ }
185
+ return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === void 0 ? void 0 : _a.trim()) || undefined };
186
+ }
187
+ TaSkillUse.parse = parse;
188
+ /** What the user typed: `/skill:name` and what follows. */
189
+ function command(use) {
190
+ return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
191
+ }
192
+ TaSkillUse.command = command;
193
+ })(TaSkillUse || (exports.TaSkillUse = TaSkillUse = {}));
194
+ /**
195
+ * The double hears of its tasks in messages of the user (`<task_update id="t1" title="…" status="done">…</task_update>`
196
+ * and the like): notes, not what the user said, which a client shows as the task they are about, and a list of
197
+ * conversations says by the task's title.
198
+ */
199
+ var TaTaskNote;
200
+ (function (TaTaskNote) {
201
+ const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
202
+ const ATTRIBUTE = /(\w+)="([^"]*)"/g;
203
+ function write(note) {
204
+ const attributes = [`id="${quote(note.id)}"`];
205
+ if (note.was !== undefined) {
206
+ attributes.push(`was="${quote(note.was)}"`);
207
+ }
208
+ attributes.push(`title="${quote(note.title)}"`);
209
+ if (note.status !== undefined) {
210
+ attributes.push(`status="${quote(note.status)}"`);
211
+ }
212
+ return `<task_${note.kind} ${attributes.join(' ')}>\n${note.body}\n</task_${note.kind}>`;
213
+ }
214
+ TaTaskNote.write = write;
215
+ /** The note `text` is, all of it; undefined for anything else. */
216
+ function parse(text) {
217
+ const match = NOTE.exec(text.trim());
218
+ if (!match) {
219
+ return undefined;
220
+ }
221
+ const attributes = {};
222
+ for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
223
+ attributes[name] = unquote(value);
224
+ }
225
+ if (!attributes.id || attributes.title === undefined) {
226
+ return undefined;
227
+ }
228
+ const { id, title, status, was } = attributes;
229
+ return { kind: match[1], id, title, ...(status ? { status } : {}), ...(was ? { was } : {}), body: match[3] };
230
+ }
231
+ TaTaskNote.parse = parse;
232
+ /** A title the model gave, in the quotes of an attribute: a quote in it would end the attribute, a new line the tag. */
233
+ function quote(text) {
234
+ return text.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/\n/g, ' ');
235
+ }
236
+ function unquote(text) {
237
+ return text.replace(/&quot;/g, '"').replace(/&amp;/g, '&');
238
+ }
239
+ })(TaTaskNote || (exports.TaTaskNote = TaTaskNote = {}));
240
+ //# sourceMappingURL=message-protocol.js.map
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Pages of Ta that ta serve may ask something (docs/design/ta-app-use.md 4.1): a page says which kinds of request it
3
+ * answers (TaPageServer.attach) and is asked one by TaClient.onPageAsk, on its own connection. A package of Ta asks
4
+ * the page of who asked its run (TaExtensionHost.pages), never another's: what one sees on their screen is theirs.
5
+ */
6
+ export declare const TaPageServer: unique symbol;
7
+ export declare const TA_PAGE_SERVICE = "TaPageServer";
8
+ /** How long a page may take to answer, unless the asker says otherwise. */
9
+ export declare const TA_PAGE_ASK_MS = 30000;
10
+ /** A request of ta serve itself: the user agrees on their screen to something an agent wants to do (TaPageConfirm). */
11
+ export declare const TA_PAGE_CONFIRM = "ta/confirm";
12
+ /** What a page says of itself (TaPageServer.attach), again as it changes. */
13
+ export interface TaPageInfo {
14
+ /** The requests it answers: `<package>/<kind>` of a web extension, `ta/<kind>` of the page itself. */
15
+ kinds: string[];
16
+ /** A phone, a tablet or a computer, as the page lays itself out. */
17
+ device: 'phone' | 'tablet' | 'computer';
18
+ /** The window of Ta Desktop: a page kept while its window is closed. */
19
+ desktop?: boolean;
20
+ /** It is in front of the user now. */
21
+ visible?: boolean;
22
+ /** The user touched, clicked or typed in it just now (a page tells it at most every few seconds). */
23
+ active?: boolean;
24
+ }
25
+ export interface TaPageServer {
26
+ attach(info: TaPageInfo): Promise<void>;
27
+ }
28
+ /** What the user is asked to agree to (TA_PAGE_CONFIRM): the answer is a boolean. */
29
+ export interface TaPageConfirm {
30
+ /** Who wants it: the name of the conversation, or of the person. */
31
+ who: string;
32
+ /** What it does, in a line of the user's language. */
33
+ what: string;
34
+ /** More, when a line is not enough. */
35
+ detail?: string;
36
+ }
37
+ /** Which page a package asks (TaHostPages.ask). */
38
+ export interface TaPageAskOptions {
39
+ /** The run that asks: the page of who asked it, the owner's for a run nobody asked. */
40
+ sessionFile?: string;
41
+ /** Or this one's page (a page that taps something). */
42
+ principal?: string;
43
+ /** How long to wait for the answer; TA_PAGE_ASK_MS without. */
44
+ timeoutMs?: number;
45
+ }
46
+ /** The pages of Ta, for the server side of a package (TaExtensionHost.pages). */
47
+ export interface TaHostPages {
48
+ /**
49
+ * Asks a page of this package (`pi.ui.answer(kind, …)` of its web extension) and resolves to its answer: the page of
50
+ * that person in front of them, else the one they touched last, else the window of Ta Desktop. Rejects when they have
51
+ * no page open that answers it, or it does not answer in time.
52
+ */
53
+ ask(kind: string, payload: unknown, options?: TaPageAskOptions): Promise<unknown>;
54
+ /** Whether that person has a page open that answers it. */
55
+ has(kind: string, options?: TaPageAskOptions): boolean;
56
+ }
57
+ //# sourceMappingURL=page-protocol.d.ts.map
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TA_PAGE_CONFIRM = exports.TA_PAGE_ASK_MS = exports.TA_PAGE_SERVICE = exports.TaPageServer = void 0;
4
+ /**
5
+ * Pages of Ta that ta serve may ask something (docs/design/ta-app-use.md 4.1): a page says which kinds of request it
6
+ * answers (TaPageServer.attach) and is asked one by TaClient.onPageAsk, on its own connection. A package of Ta asks
7
+ * the page of who asked its run (TaExtensionHost.pages), never another's: what one sees on their screen is theirs.
8
+ */
9
+ exports.TaPageServer = Symbol('TaPageServer');
10
+ exports.TA_PAGE_SERVICE = 'TaPageServer';
11
+ /** How long a page may take to answer, unless the asker says otherwise. */
12
+ exports.TA_PAGE_ASK_MS = 30000;
13
+ /** A request of ta serve itself: the user agrees on their screen to something an agent wants to do (TaPageConfirm). */
14
+ exports.TA_PAGE_CONFIRM = 'ta/confirm';
15
+ //# sourceMappingURL=page-protocol.js.map