palbase 0.13.2 → 0.14.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 (53) hide show
  1. package/dist/ai/index.js +2 -2
  2. package/dist/backend/engine.js +2 -2
  3. package/dist/backend/env.js +1 -1
  4. package/dist/backend/index.js +3 -3
  5. package/dist/backend/stack.js +1 -1
  6. package/dist/backend/test.js +2 -2
  7. package/dist/chunks/{DLQT5KPC.js → 22WJEDHI.js} +1 -1
  8. package/dist/chunks/{UMCUTNWL.js → 5LC7GWQ4.js} +2 -2
  9. package/dist/chunks/{B5XYZZDJ.js → 7MGWLEW2.js} +1 -1
  10. package/dist/chunks/{ZOF56QTG.js → AGZIRK5O.js} +2 -2
  11. package/dist/chunks/{QCZJK4GZ.js → DQ4XHMZN.js} +2 -2
  12. package/dist/chunks/FGKFL5W3.js +18 -0
  13. package/dist/chunks/{MWTLLONV.js → FQV5NKI4.js} +2 -2
  14. package/dist/chunks/{B33QXIR5.js → HQTKK3LU.js} +1 -1
  15. package/dist/chunks/{ZT4AKS6D.js → JGUZOLS4.js} +2 -2
  16. package/dist/chunks/{NRWY25JZ.js → KOR6BP5M.js} +1 -1
  17. package/dist/chunks/MDKUD5KF.js +2 -0
  18. package/dist/chunks/{53ZQBGJV.js → OG5U5HFP.js} +2 -2
  19. package/dist/chunks/{JEI4RW55.js → OIKBZFMC.js} +2 -2
  20. package/dist/chunks/{7ZSVOQFN.js → QGGRIABQ.js} +2 -2
  21. package/dist/chunks/{22JG5QKQ.js → R2FKMKIY.js} +1 -1
  22. package/dist/chunks/UUS5URWX.js +21 -0
  23. package/dist/chunks/{66QSZDXV.js → VI7VITLG.js} +2 -2
  24. package/dist/chunks/{X2BWW2WC.js → VYPEK5RA.js} +1 -1
  25. package/dist/chunks/{IYUDOOD7.js → XA7ML545.js} +2 -2
  26. package/dist/chunks/XMJ4WMD2.js +2 -0
  27. package/dist/chunks/{ABRUIWQ3.js → XUX2HR4Z.js} +1 -1
  28. package/dist/chunks/{LDZ7OKNS.js → YX4W5H7Q.js} +2 -2
  29. package/dist/chunks/{JWLK6SLN.js → ZSICMUJY.js} +2 -2
  30. package/dist/cli.js +123 -122
  31. package/dist/refuse/ai.js +1 -1
  32. package/dist/refuse/backend.js +1 -1
  33. package/dist/refuse/server.js +1 -1
  34. package/dist/server/index.js +2 -2
  35. package/dist/server/testing.js +2 -2
  36. package/dist/web/index.js +2 -2
  37. package/dist/web/message.js +2 -2
  38. package/dist/web/palbe.js +2 -2
  39. package/dist/web/paywall.js +2 -2
  40. package/dist/web/push-sw.js +1 -1
  41. package/dist/web/ssr.js +2 -2
  42. package/dist/web/vite.js +2 -2
  43. package/package.json +2 -2
  44. package/types/ai/src/ai.d.ts +34 -7
  45. package/types/ai/src/chats.d.ts +73 -7
  46. package/types/ai/src/index.d.ts +3 -3
  47. package/types/ai/src/tools.d.ts +37 -7
  48. package/types/backend/src/openapi.d.ts +22 -0
  49. package/types/internal/src/modules/ai.d.ts +259 -13
  50. package/dist/chunks/2DBSGJ7Z.js +0 -2
  51. package/dist/chunks/WAMYRYDY.js +0 -2
  52. package/dist/chunks/WUYO4O77.js +0 -18
  53. package/dist/chunks/YWEI45Q6.js +0 -21
@@ -1,20 +1,58 @@
1
1
  import { type Reply, type Transport } from '../transport.js';
2
2
  /**
3
- * A named agent of the project.
3
+ * An agent of the project's. One its backend defines (source code) is its build's: it is changed in the code, and here is what its last turn was defined as. One the project keeps (source platform) is changed as a draft, and its chats talk to the version published.
4
4
  */
5
5
  export type Agent = {
6
- definition: AgentDefinition;
6
+ /**
7
+ * Code: when its last turn was defined (absent: none yet).
8
+ */
9
+ defined_at?: string;
10
+ definition?: AgentDefinition;
11
+ /**
12
+ * What it is for: the published version's (a draft's, before one is), or a code agent's last turn's.
13
+ */
14
+ description?: string;
15
+ draft?: AgentDefinition;
16
+ /**
17
+ * Code: the instructions its last turn was told are not shown to this caller — a member of the project's team: a backend writes them from the turn's context, which may carry its user's words.
18
+ */
19
+ instructions_hidden?: boolean;
20
+ /**
21
+ * Code: the backend machine whose build defines it.
22
+ */
23
+ machine?: string;
7
24
  /**
8
25
  * Its name.
9
26
  */
10
27
  name: string;
28
+ published?: AgentDefinition;
11
29
  /**
12
- * When it was last put.
30
+ * Platform: the version published; null: none yet, and a chat started by its name is refused (agent_not_published).
13
31
  */
14
- updated_at: string;
32
+ published_version?: number | null;
33
+ /**
34
+ * Platform: the draft's revision, which a change to it names (PUT …?revision=) so that a change made meanwhile is not lost.
35
+ */
36
+ revision?: number;
37
+ /**
38
+ * code: its backend's build defines it; platform: the project keeps it (Studio, the CLI, the API).
39
+ */
40
+ source: "code" | "platform";
41
+ /**
42
+ * Platform: the draft is not the version published.
43
+ */
44
+ unpublished_changes?: boolean;
45
+ /**
46
+ * Platform: when its draft was last saved.
47
+ */
48
+ updated_at?: string;
49
+ /**
50
+ * Platform: who saved it last — a developer's id, or server for the secret key's.
51
+ */
52
+ updated_by?: string;
15
53
  };
16
54
  /**
17
- * What an agent is for a turn: its instructions, model, tools and subagents — or, for one the project's backend defines at every turn's start (the framework's ai.agent), the machine to ask (backend), alone.
55
+ * What an agent is: its instructions, model, tools and subagents, and the shape of its one-shot answers — or, for one the project's backend defined at every turn's start before its build's contract said so, the machine to ask (backend), alone.
18
56
  */
19
57
  export type AgentDefinition = {
20
58
  /**
@@ -25,6 +63,10 @@ export type AgentDefinition = {
25
63
  * The window, in tokens, the turn works in (the model's standard one unless said; more is billed as its provider bills it — GET /ai/models, context_window and max_input_tokens).
26
64
  */
27
65
  context_window?: number;
66
+ /**
67
+ * What it is for, in a sentence or two: the people who pick an agent read it, and so does the agent a subagent works for.
68
+ */
69
+ description?: string;
28
70
  /**
29
71
  * How hard the model thinks: none, minimal, low, medium, high, xhigh, max — which rungs a model takes is its catalogue entry's (GET /ai/models, efforts). Left out: the platform's.
30
72
  */
@@ -45,6 +87,12 @@ export type AgentDefinition = {
45
87
  * A role (fast, default, strong) or a catalogue model.
46
88
  */
47
89
  model?: string;
90
+ /**
91
+ * A JSON Schema a one-shot answer of the agent's is a document of (POST /ai/responses naming the agent): the same keywords a response's schema takes. A chat's turns answer in text.
92
+ */
93
+ output?: {
94
+ [key: string]: unknown;
95
+ };
48
96
  /**
49
97
  * Its subagents (16 at most).
50
98
  */
@@ -59,14 +107,94 @@ export type AgentDefinition = {
59
107
  tools?: ToolRef[];
60
108
  };
61
109
  /**
62
- * The project's named agents.
110
+ * An agent described: what it is for, who it talks to, what it may do.
111
+ */
112
+ export type AgentDraftRequest = {
113
+ /**
114
+ * The agent, in words.
115
+ */
116
+ description: string;
117
+ /**
118
+ * The name it is to have (left out: one is suggested).
119
+ */
120
+ name?: string;
121
+ };
122
+ /**
123
+ * The project's agents.
63
124
  */
64
125
  export type AgentList = {
65
126
  /**
66
- * By name.
127
+ * By name: its backend's (in the builds that serve) and those it keeps. A name two machines' builds define is neither's, and is not here.
67
128
  */
68
129
  agents: Agent[];
69
130
  };
131
+ /**
132
+ * What to publish: the draft as it is.
133
+ */
134
+ export type AgentPublish = {
135
+ /**
136
+ * The draft's revision as it was looked at: when another was saved since, the publish is refused (draft_changed). Left out: the draft as it is now.
137
+ */
138
+ revision?: number;
139
+ };
140
+ /**
141
+ * The version its chats are to talk to again.
142
+ */
143
+ export type AgentRollback = {
144
+ /**
145
+ * The draft's revision as it was looked at: going back drops a change of the draft not published, and one saved since is not dropped unseen (draft_changed).
146
+ */
147
+ revision?: number;
148
+ /**
149
+ * A version it had.
150
+ */
151
+ version: number;
152
+ };
153
+ /**
154
+ * An agent written from a description: kept nowhere until it is put (PUT /ai/agents/{name}).
155
+ */
156
+ export type AgentSuggestion = {
157
+ definition: AgentDefinition;
158
+ /**
159
+ * Its name: the one asked for, or one suggested that no agent of the project has.
160
+ */
161
+ name: string;
162
+ };
163
+ /**
164
+ * A published version of an agent the project keeps: it never changes. It goes with the agent; one made again under its name numbers its versions after it, and a chat on a gone one is told so (agent_version_not_found).
165
+ */
166
+ export type AgentVersion = {
167
+ definition: AgentDefinition;
168
+ /**
169
+ * When it was published.
170
+ */
171
+ published_at: string;
172
+ /**
173
+ * Who published it — a developer's id, or server.
174
+ */
175
+ published_by: string;
176
+ /**
177
+ * Its number: 1, then each publish one more.
178
+ */
179
+ version: number;
180
+ };
181
+ /**
182
+ * An agent's versions, newest first.
183
+ */
184
+ export type AgentVersionList = {
185
+ /**
186
+ * The cursor of the next page; absent on the last.
187
+ */
188
+ next_cursor?: string;
189
+ /**
190
+ * The version its chats talk to; null: none.
191
+ */
192
+ published_version: number | null;
193
+ /**
194
+ * Newest first.
195
+ */
196
+ versions: AgentVersion[];
197
+ };
70
198
  /**
71
199
  * A conversation of the project's users with one of its agents.
72
200
  */
@@ -75,6 +203,10 @@ export type Chat = {
75
203
  * The agent it talks to.
76
204
  */
77
205
  agent: string;
206
+ /**
207
+ * The version of the agent it stays on (agent@N); absent: the published one, at each turn.
208
+ */
209
+ agent_version?: number;
78
210
  /**
79
211
  * When it was started.
80
212
  */
@@ -347,7 +479,7 @@ export type ChatRepo = {
347
479
  */
348
480
  export type ChatRequest = {
349
481
  /**
350
- * The agent it talks to: a named agent of the project's — or, with a definition of the chat's own, the server's name for it.
482
+ * The agent it talks to: one of the project's by name — its backend's, or one it keeps, whose published version each turn takes, or name@N to stay on version N — or, with a definition of the chat's own, the server's name for it.
351
483
  */
352
484
  agent: string;
353
485
  definition?: AgentDefinition;
@@ -1501,6 +1633,10 @@ export type ResponseEventError = {
1501
1633
  * A question for a model: input, or messages.
1502
1634
  */
1503
1635
  export type ResponseRequest = {
1636
+ /**
1637
+ * An agent of the project's — its name (the version published), or name@N (version N): its instructions, model, tools and output shape the answer. A field this request names replaces the agent's for this answer alone; the agent is not changed.
1638
+ */
1639
+ agent?: string;
1504
1640
  /**
1505
1641
  * Answer at once; the response's end is the event ai.response.completed or ai.response.failed.
1506
1642
  */
@@ -1728,6 +1864,37 @@ export type TextModel = {
1728
1864
  */
1729
1865
  role: string;
1730
1866
  };
1867
+ /**
1868
+ * A tool an agent of the project's may be given, as a ToolRef names it.
1869
+ */
1870
+ export type Tool = {
1871
+ /**
1872
+ * Every call waits for a person's yes.
1873
+ */
1874
+ approval: boolean;
1875
+ /**
1876
+ * What it does.
1877
+ */
1878
+ description: string;
1879
+ /**
1880
+ * backend, client: the machine whose build declares it.
1881
+ */
1882
+ machine?: string;
1883
+ /**
1884
+ * Its name.
1885
+ */
1886
+ name: string;
1887
+ /**
1888
+ * What it takes, as a JSON Schema (an MCP server says its own when it is called).
1889
+ */
1890
+ parameters?: {
1891
+ [key: string]: unknown;
1892
+ };
1893
+ /**
1894
+ * backend: the backend's function; client: the app answers it; https, mcp: an endpoint of the project's; platform: the platform's.
1895
+ */
1896
+ source: "backend" | "client" | "https" | "mcp" | "platform";
1897
+ };
1731
1898
  /**
1732
1899
  * A part of what a tool returned.
1733
1900
  */
@@ -1749,6 +1916,15 @@ export type ToolContent = {
1749
1916
  */
1750
1917
  type: "text" | "image";
1751
1918
  };
1919
+ /**
1920
+ * The tools the project's agents may be given.
1921
+ */
1922
+ export type ToolList = {
1923
+ /**
1924
+ * The backend's (its builds that serve), the project's endpoints, then the platform's.
1925
+ */
1926
+ tools: Tool[];
1927
+ };
1752
1928
  /**
1753
1929
  * What an app's tool returned (1 MiB of text and 4 images at most).
1754
1930
  */
@@ -2406,29 +2582,52 @@ export interface Events {
2406
2582
  /** Palbase ai */
2407
2583
  export declare function client(t: Transport): {
2408
2584
  /**
2409
- * The project's named agents
2585
+ * Write an agent from a description
2410
2586
  *
2411
- * Every agent the project named, by name.
2587
+ * A definition written from a description: instructions, a model, the project's own tools that fit (named by their name: the agent follows the code), subagents and an output shape where the description calls for them. Nothing is kept: put it (PUT /ai/agents/{name}) to have it. It is a person's (a developer's session or token: 403 person_required for the secret key), the platform pays for it, and it is bounded (429 too_many_drafts): 20 an hour by a person in a project, 60 by its people, 40 by a person across their projects — and the platform's day (429 drafts_paused).
2588
+ */
2589
+ draftAgent(input: {
2590
+ body: AgentDraftRequest; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
2591
+ signal?: AbortSignal;
2592
+ }): Promise<Reply<200, AgentSuggestion>>;
2593
+ /**
2594
+ * The project's agents
2595
+ *
2596
+ * The agents the project keeps and its backend's — each one the build its machine serves defines (its contract's x-palbase-agents) — by name. A name the project keeps is that agent's, whatever a build declares.
2412
2597
  */
2413
2598
  listAgents(input?: {
2414
2599
  signal?: AbortSignal;
2415
2600
  }): Promise<Reply<200, AgentList>>;
2416
2601
  /**
2417
- * Name an agent
2602
+ * An agent
2603
+ *
2604
+ * One the project keeps: its draft, the version published and its revision. One its backend defines: its machine, and what its last turn was defined as.
2605
+ */
2606
+ getAgent(input: {
2607
+ path: {
2608
+ name: string;
2609
+ }; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
2610
+ signal?: AbortSignal;
2611
+ }): Promise<Reply<200, Agent>>;
2612
+ /**
2613
+ * Save an agent's draft
2418
2614
  *
2419
- * An agent a chat the server starts by its name talks to: its definition, or the backend machine that defines it at each turn.
2615
+ * Saves the draft of an agent the project keeps — a new one's first. What its chats talk to changes only once the draft is published. revision names the draft the change was made to: when another was saved since, it is refused (409 draft_changed) and nothing is lost; left out, the last save wins. A name its backend's build defines is refused (409 agent_defined_in_code): that agent is changed in the code. A definition of backend alone names the machine that defines the agent at each turn — the framework's agents before their build's contract said so — and is kept as it is, with no draft.
2420
2616
  */
2421
2617
  putAgent(input: {
2422
2618
  path: {
2423
2619
  name: string;
2424
2620
  };
2621
+ query?: {
2622
+ revision?: number;
2623
+ };
2425
2624
  body: AgentDefinition; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
2426
2625
  signal?: AbortSignal;
2427
2626
  }): Promise<Reply<200, Agent>>;
2428
2627
  /**
2429
2628
  * Forget an agent
2430
2629
  *
2431
- * Its chats stay; a message to one of them is refused (agent_not_found) until an agent of that name is put again.
2630
+ * An agent the project keeps, its versions with it — an agent made again under its name numbers its versions after them, and a chat on one of them is told it is gone — or a backend's put the old way. Its chats stay; a message to one of them is refused (agent_not_found) until an agent of that name is there again. One its backend's build declares goes with the code (409 agent_defined_in_code).
2432
2631
  */
2433
2632
  deleteAgent(input: {
2434
2633
  path: {
@@ -2436,6 +2635,45 @@ export declare function client(t: Transport): {
2436
2635
  }; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
2437
2636
  signal?: AbortSignal;
2438
2637
  }): Promise<Reply<204, undefined>>;
2638
+ /**
2639
+ * Publish an agent's draft
2640
+ *
2641
+ * Makes the draft a version, the next number, and the one its chats talk to from their next turn on. A draft that is the version published is refused (409 nothing_to_publish); an agent keeps 1000 versions (409 too_many_versions).
2642
+ */
2643
+ publishAgent(input: {
2644
+ path: {
2645
+ name: string;
2646
+ };
2647
+ body: AgentPublish; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
2648
+ signal?: AbortSignal;
2649
+ }): Promise<Reply<200, Agent>>;
2650
+ /**
2651
+ * Go back to a version
2652
+ *
2653
+ * Makes a version it had the one its chats talk to, and its draft that version: a change of the draft not published is dropped.
2654
+ */
2655
+ rollbackAgent(input: {
2656
+ path: {
2657
+ name: string;
2658
+ };
2659
+ body: AgentRollback; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
2660
+ signal?: AbortSignal;
2661
+ }): Promise<Reply<200, Agent>>;
2662
+ /**
2663
+ * An agent's versions
2664
+ *
2665
+ * The versions an agent the project keeps was published as, newest first.
2666
+ */
2667
+ listAgentVersions(input: {
2668
+ path: {
2669
+ name: string;
2670
+ };
2671
+ query?: {
2672
+ limit?: number; /** The next_cursor of the previous page. */
2673
+ cursor?: string;
2674
+ }; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
2675
+ signal?: AbortSignal;
2676
+ }): Promise<Reply<200, AgentVersionList>>;
2439
2677
  /**
2440
2678
  * The chats
2441
2679
  *
@@ -3074,6 +3312,14 @@ export declare function client(t: Transport): {
3074
3312
  body: SettingsRequest; /** Stops the call: the request in flight, a wait before a retry, a proof-of-work being solved. */
3075
3313
  signal?: AbortSignal;
3076
3314
  }): Promise<Reply<200, Settings>>;
3315
+ /**
3316
+ * The tools an agent may be given
3317
+ *
3318
+ * The backend's tools (each one the build its machine serves declares: its contract's x-palbase-ai-tools), the project's endpoints, and the platform's.
3319
+ */
3320
+ listTools(input?: {
3321
+ signal?: AbortSignal;
3322
+ }): Promise<Reply<200, ToolList>>;
3077
3323
  /**
3078
3324
  * What the project's use of models cost
3079
3325
  *
@@ -1,2 +0,0 @@
1
- /*! palbase 0.13.2 — Palbase SDK License (see LICENSE) */
2
- import{a as d,b as u}from"./7ZSVOQFN.js";var p={too_many_chats:()=>"this user is in as many chats as they may be (100): delete or leave one before starting another",too_many_endpoints:()=>"the project holds as many tool endpoints as it may (32): delete one (ai.endpoints.delete) before putting another",too_many_messages:t=>`this user has sent as many messages this minute as the project allows${t.retryAfter!==void 0?`: write again in ${t.retryAfter} s`:""}`,history_full:()=>"the project keeps as much chat history as it may: delete chats to write again",not_your_turn:()=>"this turn is another member's: only the member who started it (or the project's server) answers its tools and decides its approvals",not_a_member:()=>"the member the server acts as (as) is not in this chat: put them in it first (chats.members.put), or act as the server",goal_lapsed:()=>"the goal was set as a member who no longer stands where they stood then (out of the chat, or the chat no longer theirs alone): it is not resumed \u2014 clear it, or set another for the chat as it is now",goal_achieved:()=>"the goal is achieved: set a new one (chats.goal.set) to work on",turn_running:()=>"the chat's agent is at work on a turn: fork it once the turn has ended, or stop it first (chats.stop)",fork_too_large:()=>"what came before that message is more than a fork begins with (512 KiB): fork it before an earlier message",too_many_voices:t=>`this user has started as many voices this hour as the project allows (5)${t.retryAfter!==void 0?`: start again in ${t.retryAfter} s`:""}`,voice_active:()=>"another member's voice is live in this chat \u2014 one voice talks in a chat at a time: wait for it to end",not_your_voice:()=>"this voice is another member's: only its member \u2014 or the server as itself \u2014 reads, tells and closes it",voice_closed:()=>"the voice has ended: start a new one (chats.voice.start)",no_workspace:()=>"this chat works in no workspace, and files go into one: start the chat with a workspace, or send pictures as images",attachment_not_found:()=>"a picture or a file given is not one its writer may attach: a file of the project's storage \u2014 for a member, their own or a public bucket's",attachment_too_large:()=>"an attachment is past its bound: 5 MiB a picture, 15 MiB a file",attachment_changed:()=>"a file changed while it was being attached: send the message again",unsupported_image:()=>"a picture is not png, jpeg, webp or gif by its bytes: send it as a file",image_not_found:()=>"a picture given is not a file of the project's storage: upload it first (storage.from(bucket).upload(path, file)) and give that bucket and path",storage_unavailable:t=>`the project's storage did not answer when the model was to read a picture${t.retryAfter!==void 0?`: try again in ${t.retryAfter} s`:"; try again shortly"}`},g=new WeakSet;function c(t){if(!(t instanceof u)||g.has(t))return t;let r=p[t.code];if(!r)return t;let s=new u({op:t.op,status:t.status,code:t.code,message:`${r(t)} (${t.op}: ${t.status} ${t.code})`,requestId:t.requestId,retryAfter:t.retryAfter,body:t.body,cause:t});return g.add(s),s}function h(t){return t.catch(r=>{throw c(r)})}function _(t){if(typeof t!="object"||t===null)return;let r=t,s=r.data;if(typeof r.type!="string"||typeof s!="object"||s===null||Array.isArray(s))return;let e=d(s),i=typeof r.id=="number"&&Number.isSafeInteger(r.id)?r.id:0;switch(r.type){case"message":return typeof e.client_id=="string"?{type:"message",seq:i,message:e}:void 0;case"turn":{if(typeof e.response_id!="string"||typeof e.status!="string")return;let n={...e,type:"turn",seq:i};return n.waiting??=null,n.error??=null,n}case"text":{let n=e.offset;return typeof e.response_id!="string"||typeof n!="number"||!Number.isInteger(n)||n<0?void 0:{type:"text",response_id:e.response_id,offset:n,text:typeof e.text=="string"?e.text:""}}case"reset":{let n=e.offset;return typeof e.response_id!="string"||typeof n!="number"||!Number.isInteger(n)||n<0?void 0:{type:"reset",response_id:e.response_id,offset:n}}case"tool":{if(typeof e.call_id!="string"||typeof e.response_id!="string")return;let n=e.omitted_bytes;return{...e,type:"tool",seq:i,omittedBytes:typeof n=="number"&&Number.isSafeInteger(n)&&n>0?n:0,outputTruncated:e.output_truncated===!0}}case"agent":return typeof e.parent_response_id=="string"?{...e,type:"agent",seq:i}:void 0;case"thinking":{if(typeof e.response_id!="string")return;let n=typeof e.run_id=="string"?e.run_id:"";return e.unavailable===!0?{type:"thinking",seq:i,response_id:e.response_id,run_id:n,text:"",unavailable:!0,model:typeof e.model=="string"?e.model:"",reason:typeof e.reason=="string"?e.reason:""}:typeof e.text!="string"?void 0:{type:"thinking",seq:i,response_id:e.response_id,run_id:n,...typeof e.step_id=="string"&&e.step_id!==""?{step_id:e.step_id}:{},text:e.text}}case"goal":{if(typeof e.goal_id!="string"||typeof e.kind!="string")return;let{seq:n,...o}=e;return{...o,type:"goal",seq:i,...typeof n=="number"?{turn:n}:{}}}case"history":{if(!Array.isArray(e.items)||typeof e.part!="number"||!Number.isInteger(e.part)||e.part<0)return;let n=e.items.filter(a=>typeof a=="object"&&a!==null&&(a.role==="user"||a.role==="assistant")&&typeof a.text=="string"),o=e.forked_from;return{type:"history",forked_from:o&&typeof o.chat_id=="string"?o:null,part:e.part,parts:typeof e.parts=="number"?e.parts:e.part+1,items:n}}case"voice":return typeof e.voice_id!="string"||e.voice_id===""||typeof e.status!="string"?void 0:{...e,type:"voice",seq:i,user_id:typeof e.user_id=="string"?e.user_id:null};case"transcript":return typeof e.id!="string"||e.id===""||typeof e.text!="string"?void 0:{type:"transcript",seq:i,id:e.id,voice_id:typeof e.voice_id=="string"?e.voice_id:"",role:typeof e.role=="string"?e.role:"",user_id:typeof e.user_id=="string"?e.user_id:null,author_name:typeof e.author_name=="string"?e.author_name:"",text:e.text,final:e.final!==!1,created_at:typeof e.created_at=="string"?e.created_at:""};default:return}}function b(t){let r=0;for(let s=0;s<t.length;s++){let e=t.charCodeAt(s);e<128?r+=1:e<2048?r+=2:e>=55296&&e<=56319&&s+1<t.length&&(t.charCodeAt(s+1)&64512)===56320?(r+=4,s++):r+=3}return r}function l(t,r){if(r<=0)return 0;let s=0;for(let e=0;e<t.length;e++){let i=t.charCodeAt(e),n=3,o=1;if(i<128?n=1:i<2048?n=2:i>=55296&&i<=56319&&e+1<t.length&&(t.charCodeAt(e+1)&64512)===56320&&(n=4,o=2),s+=n,s>=r)return e+o;e+=o-1}return t.length}function v(t,r){return t.slice(l(t,r))}export{h as a,_ as b,b as c,l as d,v as e};