@stacknet/stacks 0.1.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 (71) hide show
  1. package/README.md +103 -0
  2. package/dist/billing-BaJlf_S8.d.cts +1154 -0
  3. package/dist/billing-BaJlf_S8.d.ts +1154 -0
  4. package/dist/clients/index.cjs +4 -0
  5. package/dist/clients/index.d.cts +752 -0
  6. package/dist/clients/index.d.ts +752 -0
  7. package/dist/clients/index.js +4 -0
  8. package/dist/index-DVzKiF_0.d.cts +198 -0
  9. package/dist/index-DVzKiF_0.d.ts +198 -0
  10. package/dist/index.cjs +17 -0
  11. package/dist/index.d.cts +309 -0
  12. package/dist/index.d.ts +309 -0
  13. package/dist/index.js +17 -0
  14. package/dist/proxy/index.cjs +2 -0
  15. package/dist/proxy/index.d.cts +1 -0
  16. package/dist/proxy/index.d.ts +1 -0
  17. package/dist/proxy/index.js +2 -0
  18. package/dist/streaming/index.cjs +13 -0
  19. package/dist/streaming/index.d.cts +145 -0
  20. package/dist/streaming/index.d.ts +145 -0
  21. package/dist/streaming/index.js +13 -0
  22. package/dist/types/index.cjs +1 -0
  23. package/dist/types/index.d.cts +335 -0
  24. package/dist/types/index.d.ts +335 -0
  25. package/dist/types/index.js +1 -0
  26. package/package.json +75 -0
  27. package/src/clients/agents.ts +233 -0
  28. package/src/clients/billing.ts +157 -0
  29. package/src/clients/coder.ts +655 -0
  30. package/src/clients/files.ts +86 -0
  31. package/src/clients/index.ts +93 -0
  32. package/src/clients/magma.ts +299 -0
  33. package/src/clients/mcp.ts +208 -0
  34. package/src/clients/network.ts +118 -0
  35. package/src/clients/points.ts +403 -0
  36. package/src/clients/skills.ts +236 -0
  37. package/src/clients/social.ts +286 -0
  38. package/src/clients/stack-management.ts +279 -0
  39. package/src/clients/task-network.ts +303 -0
  40. package/src/clients/user.ts +84 -0
  41. package/src/clients/widgets.ts +171 -0
  42. package/src/index.ts +387 -0
  43. package/src/managers/index.ts +10 -0
  44. package/src/managers/task-manager.ts +310 -0
  45. package/src/proxy/forwarder.ts +146 -0
  46. package/src/proxy/index.ts +32 -0
  47. package/src/proxy/route-handlers.ts +950 -0
  48. package/src/streaming/component-stream.ts +319 -0
  49. package/src/streaming/index.ts +21 -0
  50. package/src/streaming/sse.ts +241 -0
  51. package/src/types/agent.ts +106 -0
  52. package/src/types/billing.ts +87 -0
  53. package/src/types/chat.ts +58 -0
  54. package/src/types/coder.ts +345 -0
  55. package/src/types/credential.ts +111 -0
  56. package/src/types/file.ts +15 -0
  57. package/src/types/imagination.ts +50 -0
  58. package/src/types/index.ts +20 -0
  59. package/src/types/mcp.ts +35 -0
  60. package/src/types/network.ts +97 -0
  61. package/src/types/points.ts +250 -0
  62. package/src/types/skill.ts +107 -0
  63. package/src/types/social.ts +109 -0
  64. package/src/types/stack.ts +269 -0
  65. package/src/types/task.ts +41 -0
  66. package/src/types/user.ts +29 -0
  67. package/src/types/widget.ts +57 -0
  68. package/src/utils/constants.ts +26 -0
  69. package/src/utils/errors.ts +169 -0
  70. package/src/utils/helpers.ts +85 -0
  71. package/src/utils/index.ts +7 -0
@@ -0,0 +1,145 @@
1
+ /**
2
+ * SSE (Server-Sent Events) streaming utilities
3
+ */
4
+ interface SSEEvent {
5
+ event?: string;
6
+ data: unknown;
7
+ id?: string;
8
+ retry?: number;
9
+ }
10
+ /**
11
+ * Parse SSE stream from a Response
12
+ */
13
+ declare function parseSSEStream(response: Response): AsyncIterable<SSEEvent>;
14
+ /**
15
+ * Create an SSE Response from an async iterable
16
+ */
17
+ declare function createSSEResponse(stream: AsyncIterable<SSEEvent>, headers?: Record<string, string>): Response;
18
+ /**
19
+ * Create an SSE writer for streaming events
20
+ */
21
+ declare class SSEWriter {
22
+ private encoder;
23
+ private controller;
24
+ private stream;
25
+ constructor();
26
+ /**
27
+ * Get the underlying ReadableStream
28
+ */
29
+ getStream(): ReadableStream<Uint8Array>;
30
+ /**
31
+ * Get a Response object for this stream
32
+ */
33
+ getResponse(headers?: Record<string, string>): Response;
34
+ /**
35
+ * Write an SSE event
36
+ */
37
+ write(event: SSEEvent): void;
38
+ /**
39
+ * Write a data-only event
40
+ */
41
+ writeData(data: unknown): void;
42
+ /**
43
+ * Write a comment (for keep-alive)
44
+ */
45
+ writeComment(comment: string): void;
46
+ /**
47
+ * Close the stream
48
+ */
49
+ close(): void;
50
+ /**
51
+ * Signal an error
52
+ */
53
+ error(err: Error): void;
54
+ }
55
+ /**
56
+ * Create an SSE writer
57
+ */
58
+ declare function createSSEWriter(): SSEWriter;
59
+
60
+ /**
61
+ * Component Streaming - Artifact streaming adapter
62
+ *
63
+ * Converts tool call responses to artifact data stream format
64
+ */
65
+ interface DataStreamWriter {
66
+ write(data: {
67
+ type: string;
68
+ data: unknown;
69
+ transient?: boolean;
70
+ }): void;
71
+ }
72
+ interface ArtifactToolCall {
73
+ id: string;
74
+ type: 'function';
75
+ function: {
76
+ name: string;
77
+ arguments: string;
78
+ };
79
+ }
80
+ interface ArtifactToolResult {
81
+ type: string;
82
+ id?: string;
83
+ title?: string;
84
+ kind?: string;
85
+ content?: string;
86
+ message?: string;
87
+ [key: string]: unknown;
88
+ }
89
+ /**
90
+ * Artifact streaming adapter for AI SDK integration
91
+ */
92
+ declare class ComponentStreamAdapter {
93
+ private dataStream;
94
+ constructor(dataStream: DataStreamWriter);
95
+ /**
96
+ * Process tool calls and convert to artifact stream events
97
+ */
98
+ processToolCalls(toolCalls: ArtifactToolCall[]): void;
99
+ /**
100
+ * Process tool results
101
+ */
102
+ processToolResult(result: ArtifactToolResult): void;
103
+ /**
104
+ * Stream an artifact with metadata
105
+ */
106
+ streamArtifact(artifact: {
107
+ id: string;
108
+ kind: string;
109
+ title: string;
110
+ content: string;
111
+ }): void;
112
+ /**
113
+ * Stream a text delta
114
+ */
115
+ streamTextDelta(delta: string): void;
116
+ /**
117
+ * Stream content in chunks
118
+ */
119
+ streamContent(content: string, chunkSize?: number): void;
120
+ /**
121
+ * Signal finish
122
+ */
123
+ finish(): void;
124
+ private handleCreateDocument;
125
+ private handleUpdateDocument;
126
+ private handleArtifactResult;
127
+ private handleArtifactUpdate;
128
+ private splitIntoChunks;
129
+ }
130
+ /**
131
+ * Helper to detect tool calls in a message
132
+ */
133
+ declare function hasToolCalls(message: {
134
+ tool_calls?: unknown[];
135
+ }): boolean;
136
+ /**
137
+ * Helper to extract tool results from content
138
+ */
139
+ declare function extractToolResults(content: string): ArtifactToolResult[];
140
+ /**
141
+ * Factory function
142
+ */
143
+ declare function createComponentStreamAdapter(dataStream: DataStreamWriter): ComponentStreamAdapter;
144
+
145
+ export { type ArtifactToolCall, type ArtifactToolResult, ComponentStreamAdapter, type DataStreamWriter, type SSEEvent, SSEWriter, createComponentStreamAdapter, createSSEResponse, createSSEWriter, extractToolResults, hasToolCalls, parseSSEStream };
@@ -0,0 +1,145 @@
1
+ /**
2
+ * SSE (Server-Sent Events) streaming utilities
3
+ */
4
+ interface SSEEvent {
5
+ event?: string;
6
+ data: unknown;
7
+ id?: string;
8
+ retry?: number;
9
+ }
10
+ /**
11
+ * Parse SSE stream from a Response
12
+ */
13
+ declare function parseSSEStream(response: Response): AsyncIterable<SSEEvent>;
14
+ /**
15
+ * Create an SSE Response from an async iterable
16
+ */
17
+ declare function createSSEResponse(stream: AsyncIterable<SSEEvent>, headers?: Record<string, string>): Response;
18
+ /**
19
+ * Create an SSE writer for streaming events
20
+ */
21
+ declare class SSEWriter {
22
+ private encoder;
23
+ private controller;
24
+ private stream;
25
+ constructor();
26
+ /**
27
+ * Get the underlying ReadableStream
28
+ */
29
+ getStream(): ReadableStream<Uint8Array>;
30
+ /**
31
+ * Get a Response object for this stream
32
+ */
33
+ getResponse(headers?: Record<string, string>): Response;
34
+ /**
35
+ * Write an SSE event
36
+ */
37
+ write(event: SSEEvent): void;
38
+ /**
39
+ * Write a data-only event
40
+ */
41
+ writeData(data: unknown): void;
42
+ /**
43
+ * Write a comment (for keep-alive)
44
+ */
45
+ writeComment(comment: string): void;
46
+ /**
47
+ * Close the stream
48
+ */
49
+ close(): void;
50
+ /**
51
+ * Signal an error
52
+ */
53
+ error(err: Error): void;
54
+ }
55
+ /**
56
+ * Create an SSE writer
57
+ */
58
+ declare function createSSEWriter(): SSEWriter;
59
+
60
+ /**
61
+ * Component Streaming - Artifact streaming adapter
62
+ *
63
+ * Converts tool call responses to artifact data stream format
64
+ */
65
+ interface DataStreamWriter {
66
+ write(data: {
67
+ type: string;
68
+ data: unknown;
69
+ transient?: boolean;
70
+ }): void;
71
+ }
72
+ interface ArtifactToolCall {
73
+ id: string;
74
+ type: 'function';
75
+ function: {
76
+ name: string;
77
+ arguments: string;
78
+ };
79
+ }
80
+ interface ArtifactToolResult {
81
+ type: string;
82
+ id?: string;
83
+ title?: string;
84
+ kind?: string;
85
+ content?: string;
86
+ message?: string;
87
+ [key: string]: unknown;
88
+ }
89
+ /**
90
+ * Artifact streaming adapter for AI SDK integration
91
+ */
92
+ declare class ComponentStreamAdapter {
93
+ private dataStream;
94
+ constructor(dataStream: DataStreamWriter);
95
+ /**
96
+ * Process tool calls and convert to artifact stream events
97
+ */
98
+ processToolCalls(toolCalls: ArtifactToolCall[]): void;
99
+ /**
100
+ * Process tool results
101
+ */
102
+ processToolResult(result: ArtifactToolResult): void;
103
+ /**
104
+ * Stream an artifact with metadata
105
+ */
106
+ streamArtifact(artifact: {
107
+ id: string;
108
+ kind: string;
109
+ title: string;
110
+ content: string;
111
+ }): void;
112
+ /**
113
+ * Stream a text delta
114
+ */
115
+ streamTextDelta(delta: string): void;
116
+ /**
117
+ * Stream content in chunks
118
+ */
119
+ streamContent(content: string, chunkSize?: number): void;
120
+ /**
121
+ * Signal finish
122
+ */
123
+ finish(): void;
124
+ private handleCreateDocument;
125
+ private handleUpdateDocument;
126
+ private handleArtifactResult;
127
+ private handleArtifactUpdate;
128
+ private splitIntoChunks;
129
+ }
130
+ /**
131
+ * Helper to detect tool calls in a message
132
+ */
133
+ declare function hasToolCalls(message: {
134
+ tool_calls?: unknown[];
135
+ }): boolean;
136
+ /**
137
+ * Helper to extract tool results from content
138
+ */
139
+ declare function extractToolResults(content: string): ArtifactToolResult[];
140
+ /**
141
+ * Factory function
142
+ */
143
+ declare function createComponentStreamAdapter(dataStream: DataStreamWriter): ComponentStreamAdapter;
144
+
145
+ export { type ArtifactToolCall, type ArtifactToolResult, ComponentStreamAdapter, type DataStreamWriter, type SSEEvent, SSEWriter, createComponentStreamAdapter, createSSEResponse, createSSEWriter, extractToolResults, hasToolCalls, parseSSEStream };
@@ -0,0 +1,13 @@
1
+ var m={"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"};async function*S(i){if(!i.body)throw new Error("Response body is null");let t=i.body.getReader(),r=new TextDecoder,n="",e={};try{for(;;){let{done:a,value:o}=await t.read();if(a)break;n+=r.decode(o,{stream:!0});let s=n.split(`
2
+ `);n=s.pop()||"";for(let c of s){if(c===""){e.data!==void 0&&(yield e),e={};continue}if(c.startsWith(":"))continue;let u=c.indexOf(":");if(u===-1)continue;let f=c.slice(0,u),l=c.slice(u+1).trimStart();switch(f){case "event":e.event=l;break;case "data":try{e.data=JSON.parse(l);}catch{e.data=l;}break;case "id":e.id=l;break;case "retry":e.retry=parseInt(l,10);break}}}e.data!==void 0&&(yield e);}finally{t.releaseLock();}}function h(i,t){let r=new TextEncoder,n=new ReadableStream({async start(e){try{for await(let a of i){let o="";a.event&&(o+=`event: ${a.event}
3
+ `),a.id&&(o+=`id: ${a.id}
4
+ `),a.retry&&(o+=`retry: ${a.retry}
5
+ `);let s=typeof a.data=="string"?a.data:JSON.stringify(a.data);o+=`data: ${s}
6
+
7
+ `,e.enqueue(r.encode(o));}}catch(a){console.error("SSE stream error:",a);}finally{e.close();}}});return new Response(n,{headers:{...m,...t}})}var d=class{encoder=new TextEncoder;controller=null;stream;constructor(){this.stream=new ReadableStream({start:t=>{this.controller=t;}});}getStream(){return this.stream}getResponse(t){return new Response(this.stream,{headers:{...m,...t}})}write(t){if(!this.controller)return;let r="";t.event&&(r+=`event: ${t.event}
8
+ `),t.id&&(r+=`id: ${t.id}
9
+ `);let n=typeof t.data=="string"?t.data:JSON.stringify(t.data);r+=`data: ${n}
10
+
11
+ `,this.controller.enqueue(this.encoder.encode(r));}writeData(t){this.write({data:t});}writeComment(t){this.controller&&this.controller.enqueue(this.encoder.encode(`: ${t}
12
+
13
+ `));}close(){this.controller&&(this.controller.close(),this.controller=null);}error(t){this.controller&&(this.controller.error(t),this.controller=null);}};function g(){return new d}var p=class{constructor(t){this.dataStream=t;}processToolCalls(t){if(!(!t||t.length===0))for(let r of t)try{let n=JSON.parse(r.function.arguments),e=r.function.name;switch(e){case "create_document":this.handleCreateDocument(n,r.id);break;case "update_document":this.handleUpdateDocument(n,r.id);break;default:console.log(`[ComponentStream] Unknown tool: ${e}`);}}catch(n){console.error("[ComponentStream] Error processing tool call:",n);}}processToolResult(t){try{t.type==="artifact"?this.handleArtifactResult(t):t.type==="artifact_update"&&this.handleArtifactUpdate(t);}catch(r){console.error("[ComponentStream] Error processing tool result:",r);}}streamArtifact(t){this.dataStream.write({type:"data-kind",data:t.kind,transient:true}),this.dataStream.write({type:"data-id",data:t.id,transient:true}),this.dataStream.write({type:"data-title",data:t.title,transient:true}),this.dataStream.write({type:"data-clear",data:null,transient:true}),this.streamContent(t.content),this.dataStream.write({type:"data-finish",data:null,transient:true});}streamTextDelta(t){this.dataStream.write({type:"data-textDelta",data:t,transient:true});}streamContent(t,r=50){let n=this.splitIntoChunks(t,r);for(let e of n)this.dataStream.write({type:"data-textDelta",data:e,transient:true});}finish(){this.dataStream.write({type:"data-finish",data:null,transient:true});}handleCreateDocument(t,r){let{title:n,kind:e,content:a}=t,o=`doc_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;console.log(`[ComponentStream] Creating document: ${n} (${e})`),this.streamArtifact({id:o,kind:e,title:n,content:a}),this.dataStream.write({type:"tool-result",data:{toolCallId:r,toolName:"create_document",result:{id:o,title:n,kind:e,message:"Document created successfully"}}});}handleUpdateDocument(t,r){let{id:n,description:e,content:a}=t;console.log(`[ComponentStream] Updating document: ${n}`),this.dataStream.write({type:"data-clear",data:null,transient:true}),this.streamContent(a),this.dataStream.write({type:"data-finish",data:null,transient:true}),this.dataStream.write({type:"tool-result",data:{toolCallId:r,toolName:"update_document",result:{id:n,message:`Document updated: ${e}`}}});}handleArtifactResult(t){let{id:r,title:n,kind:e,content:a}=t;if(!r||!n||!e||!a){console.error("[ComponentStream] Invalid artifact result:",t);return}this.streamArtifact({id:r,kind:e,title:n,content:a});}handleArtifactUpdate(t){let{content:r}=t;if(!r){console.error("[ComponentStream] Invalid artifact update:",t);return}this.dataStream.write({type:"data-clear",data:null,transient:true}),this.streamContent(r),this.dataStream.write({type:"data-finish",data:null,transient:true});}splitIntoChunks(t,r){let n=[],e=t.split(" "),a="";for(let o=0;o<e.length;o++){let s=o===0?e[o]:" "+e[o];a.length+s.length>r&&a.length>0?(n.push(a),a=s.trim()):a+=s;}return a.length>0&&n.push(a),n}};function y(i){return !!(i?.tool_calls&&Array.isArray(i.tool_calls)&&i.tool_calls.length>0)}function E(i){try{let t=JSON.parse(i);if(t.type&&(t.type==="artifact"||t.type==="artifact_update"))return [t]}catch{}return []}function v(i){return new p(i)}export{p as ComponentStreamAdapter,d as SSEWriter,v as createComponentStreamAdapter,h as createSSEResponse,g as createSSEWriter,E as extractToolResults,y as hasToolCalls,S as parseSSEStream};
@@ -0,0 +1 @@
1
+ 'use strict';var o={text_input:1,image_input:2,file_input:4,audio_input:8,video_input:16,music_input:32,text_output:64,image_output:128,audio_output:256,video_output:512,embeddings_output:1024,music_output:2048,skills:4096,loops:8192,tools:16384,pipelines:32768,training:65536},n=131071;function a(t){let e=0;for(let[i,r]of Object.entries(o))t[i]&&(e|=r);return e}function s(t){let e={};for(let[i,r]of Object.entries(o))e[i]=(t&r)!==0;return e}exports.ALL_CAPABILITIES_BITMASK=n;exports.CAPABILITY_BITS=o;exports.bitmaskToCapabilities=s;exports.capabilitiesToBitmask=a;
@@ -0,0 +1,335 @@
1
+ export { A as ALL_CAPABILITIES_BITMASK, c as ActionProof, d as AddPointsInput, e as Agent, f as AgentCreateInput, g as AgentExecuteRequest, h as AgentExecuteResponse, i as AgentFromPromptInput, j as AgentResponse, k as AgentTrigger, l as AgentUpdateInput, m as AgentWorkflow, n as AgentWorkflowEdge, o as AgentWorkflowNode, p as AgentsClientConfig, q as AgentsListResponse, r as AllowlistConfig, s as AllowlistMode, t as AllowlistUpdateInput, u as AuthMetrics, B as BillingClientConfig, v as BillingPlan, w as BillingPlansResponse, x as BillingPortalResponse, y as BillingState, z as BillingTier, C as CAPABILITY_BITS, D as CapabilityKey, E as ChatCompletionChunk, F as ChatCompletionRequest, G as ChatCompletionResponse, H as CommentResponse, I as CommentsResponse, J as ConfigureOAuthInput, K as ConfigureStripeInput, L as ConfigureWeb3Input, M as ConsensusStateSummary, N as ConsensusStatus, O as ContextDomain, P as ContextResponse, Q as ContextsListResponse, R as CreateCheckoutSessionResponse, S as CreateContextInput, U as CreateDelegationInput, V as CreateDomainInput, W as CreateKeyResponse, X as CreatePostInput, Y as CreatePostResponse, Z as CreateStackRequest, _ as Delegation, $ as DelegationChainLink, a0 as DelegationFilters, a1 as DelegationResponse, a2 as DelegationScope, a3 as DelegationsListResponse, a4 as DomainResponse, a5 as DomainsListResponse, a6 as FeedResponse, a7 as FileUploadResponse, a8 as FilesClientConfig, a9 as HistoryFilters, aa as HistoryResponse, ab as ImaginationCharacter, ac as ImaginationMetadata, ad as ImaginationSource, ae as InitNetworkResponse, af as LeaderStatus, ag as LikeCheckResponse, ah as LikeResponse, ai as MCPContent, aj as MCPMessage, ak as MCPSession, al as MCPSessionConfig, am as MCPToolResult, an as MPCNode, ao as MagmaFile, ap as MediaType, aq as Message, ar as MeteredUsage, as as ModelLayerInfo, at as ModelLayersResponse, au as NetworkClientConfig, av as NetworkStatus, br as Orientation, aw as PaginationMeta, ax as PaymentRequiredResponse, ay as PointBalance, az as PointContext, aA as PointRecord, aB as PointRecordResponse, aC as PointSpend, aD as PointSpendResponse, aE as PointsClientConfig, aF as PostResponse, aG as ProfileResponse, aH as RemixesResponse, aI as Skill, aJ as SkillCreateInput, bp as SkillMapPromptResponse, bo as SkillMapResponse, aK as SkillResponse, bq as SkillSummaryResponse, aL as SkillUpdateInput, bn as SkillVerifyResponse, aM as SkillsClientConfig, aN as SkillsListResponse, aO as SocialAuthor, aP as SocialClientConfig, aQ as SocialComment, aR as SocialPost, aS as SocialRemix, aT as SpendDestination, aU as SpendPointsInput, aV as StackCapabilities, aW as StackConfig, aX as StackKeyInfo, aY as StackKeysListResponse, aZ as StackListResponse, a_ as StackManagementClientConfig, a$ as StackMember, b0 as StackMemberStats, b1 as StackModelAlias, b2 as StackOAuthProvider, b3 as StackResponse, b4 as StackStripeProvider, b5 as StackWeb3Provider, b6 as TaskPayload, b7 as TaskResponse, a as TaskState, b as TaskStatus, T as TaskType, b8 as UsageRecord, b9 as UserClientConfig, ba as UserProfile, bb as UserProfileResponse, bc as UserProfileUpdateInput, bd as Widget, be as WidgetCreateInput, bf as WidgetResponse, bg as WidgetSystemPromptResponse, bh as WidgetUpdateInput, bi as WidgetsClientConfig, bj as WidgetsListResponse, bk as WorkflowData, bl as bitmaskToCapabilities, bm as capabilitiesToBitmask } from '../billing-BaJlf_S8.cjs';
2
+
3
+ /**
4
+ * Coder type definitions
5
+ * Types for the GeoffCoder AI coding agent
6
+ */
7
+ type CoderSessionStatus = 'active' | 'completed' | 'aborted' | 'error';
8
+ interface CoderSession {
9
+ id: string;
10
+ workingDirectory: string;
11
+ status: CoderSessionStatus;
12
+ createdAt: string;
13
+ updatedAt?: string;
14
+ metrics: CoderMetrics;
15
+ sandboxId?: string;
16
+ }
17
+ interface CoderMetrics {
18
+ tokensUsed: number;
19
+ promptTokens: number;
20
+ completionTokens: number;
21
+ contextSize: number;
22
+ filesCreated: number;
23
+ filesModified: number;
24
+ linesAdded: number;
25
+ linesRemoved: number;
26
+ commandsExecuted: number;
27
+ toolCallsTotal: number;
28
+ apiCalls: number;
29
+ startTime: number;
30
+ endTime?: number;
31
+ modifiedFiles: string[];
32
+ createdFiles: string[];
33
+ }
34
+ interface CoderExecuteRequest {
35
+ /** The prompt/task for the coder agent */
36
+ prompt: string;
37
+ /** Working directory for file operations */
38
+ workingDirectory?: string;
39
+ /** Maximum iterations for the agent loop */
40
+ maxIterations?: number;
41
+ /** Model to use for completions */
42
+ model?: string;
43
+ /** Maximum tokens per response */
44
+ maxTokens?: number;
45
+ /** Temperature for generation */
46
+ temperature?: number;
47
+ /** Whether to stream the response */
48
+ stream?: boolean;
49
+ /** Existing session ID to continue */
50
+ sessionId?: string;
51
+ /** Existing sandbox ID to use (from frontend) */
52
+ sandboxId?: string;
53
+ /** E2B sandbox configuration */
54
+ sandbox?: CoderSandboxConfig;
55
+ /** Chat ID for session tracking and approval responses */
56
+ chatId?: string;
57
+ /** API base URL for self-hosted inference endpoint */
58
+ apiBase?: string;
59
+ /** API key for authentication */
60
+ apiKey?: string;
61
+ /** Auto-approve tool execution (default: true for backward compatibility) */
62
+ autoApprove?: boolean;
63
+ /** Tool permission overrides */
64
+ toolPermissions?: Record<string, {
65
+ permission: 'always' | 'ask' | 'never';
66
+ allowlist?: string[];
67
+ denylist?: string[];
68
+ }>;
69
+ }
70
+ interface CoderSandboxConfig {
71
+ /** Enable sandbox execution */
72
+ enabled: boolean;
73
+ /** Sandbox template (e.g., 'node', 'python', 'nextjs') */
74
+ template?: string;
75
+ /** Session timeout in seconds */
76
+ timeout?: number;
77
+ /** Environment variables */
78
+ env?: Record<string, string>;
79
+ /** Packages to pre-install */
80
+ packages?: string[];
81
+ }
82
+ interface CoderExecuteResponse {
83
+ sessionId: string;
84
+ status: CoderSessionStatus;
85
+ result?: string;
86
+ error?: string;
87
+ metrics: CoderMetrics;
88
+ }
89
+ type CoderStreamEventType = 'session_start' | 'thinking' | 'tool_call' | 'tool_result' | 'assistant_message' | 'progress' | 'metrics_update' | 'session_complete' | 'complete' | 'file_written' | 'file_modified' | 'sandbox_info' | 'session_files' | 'text' | 'done' | 'error' | 'approval_required' | 'approval_response' | 'tool_blocked' | 'context_compacted' | 'background_process_started' | 'background_process_completed' | 'session_saved' | 'session_resumed' | 'file_checkpoint' | 'memory_loaded' | 'question_asked' | 'question_answered' | 'blueprint_generated' | 'plan_progress' | 'token_usage' | 'task_created' | 'task_update';
90
+ interface CoderStreamEvent {
91
+ type: CoderStreamEventType;
92
+ data: unknown;
93
+ timestamp: number;
94
+ }
95
+ interface CoderThinkingEvent {
96
+ type: 'thinking';
97
+ data: {
98
+ content: string;
99
+ iteration: number;
100
+ };
101
+ }
102
+ interface CoderToolCallEvent {
103
+ type: 'tool_call';
104
+ data: {
105
+ toolName: string;
106
+ arguments: Record<string, unknown>;
107
+ toolCallId: string;
108
+ };
109
+ }
110
+ interface CoderToolResultEvent {
111
+ type: 'tool_result';
112
+ data: {
113
+ toolCallId: string;
114
+ toolName: string;
115
+ success: boolean;
116
+ output: string;
117
+ error?: string;
118
+ };
119
+ }
120
+ interface CoderProgressEvent {
121
+ type: 'progress';
122
+ data: {
123
+ iteration: number;
124
+ maxIterations: number;
125
+ currentAction: string;
126
+ };
127
+ }
128
+ interface CoderTool {
129
+ name: string;
130
+ description: string;
131
+ parameters: {
132
+ type: 'object';
133
+ properties: Record<string, CoderToolParameter>;
134
+ required?: string[];
135
+ };
136
+ }
137
+ interface CoderToolParameter {
138
+ type: string;
139
+ description: string;
140
+ enum?: string[];
141
+ }
142
+ interface CoderToolResult {
143
+ success: boolean;
144
+ output: string;
145
+ error?: string;
146
+ }
147
+ interface CoderFileInfo {
148
+ name: string;
149
+ path: string;
150
+ size: number;
151
+ isDirectory: boolean;
152
+ modified?: string;
153
+ children?: CoderFileInfo[];
154
+ }
155
+ interface CoderFileContent {
156
+ path: string;
157
+ content: string;
158
+ encoding?: 'utf8' | 'base64';
159
+ size: number;
160
+ }
161
+ interface CoderFileWriteInput {
162
+ path: string;
163
+ content: string;
164
+ encoding?: 'utf8' | 'base64';
165
+ createDirectories?: boolean;
166
+ }
167
+ interface CoderSearchResult {
168
+ file: string;
169
+ line: number;
170
+ content: string;
171
+ contextBefore?: string[];
172
+ contextAfter?: string[];
173
+ }
174
+ interface CoderDiffInput {
175
+ path: string;
176
+ original: string;
177
+ replacement: string;
178
+ replaceAll?: boolean;
179
+ }
180
+ interface CoderCommandResult {
181
+ stdout: string;
182
+ stderr: string;
183
+ exitCode: number;
184
+ executionTimeMs: number;
185
+ }
186
+ interface CoderCommandInput {
187
+ command: string;
188
+ timeout?: number;
189
+ cwd?: string;
190
+ }
191
+ interface CoderSandbox {
192
+ id: string;
193
+ status: 'creating' | 'ready' | 'busy' | 'stopped' | 'error';
194
+ template: string;
195
+ workingDirectory: string;
196
+ createdAt: string;
197
+ expiresAt?: string;
198
+ }
199
+ interface CoderSandboxCreateInput {
200
+ template?: string;
201
+ timeout?: number;
202
+ env?: Record<string, string>;
203
+ packages?: string[];
204
+ }
205
+ interface CoderSandboxExecInput {
206
+ command: string;
207
+ timeout?: number;
208
+ stream?: boolean;
209
+ }
210
+ interface CoderSandboxExecResult {
211
+ stdout: string;
212
+ stderr: string;
213
+ exitCode: number;
214
+ executionTimeMs: number;
215
+ }
216
+ interface CoderSessionResponse {
217
+ session: CoderSession;
218
+ }
219
+ interface CoderSessionsListResponse {
220
+ sessions: CoderSession[];
221
+ }
222
+ interface CoderToolsResponse {
223
+ tools: CoderTool[];
224
+ }
225
+ interface CoderFilesResponse {
226
+ files: CoderFileInfo[];
227
+ path: string;
228
+ }
229
+ interface CoderSandboxResponse {
230
+ sandbox: CoderSandbox;
231
+ }
232
+ interface CoderClientConfig {
233
+ /** Base URL for the task network API */
234
+ baseUrl?: string;
235
+ /** API key for authentication */
236
+ apiKey?: string;
237
+ /** Request timeout in milliseconds */
238
+ timeout?: number;
239
+ /** Default model for coder sessions */
240
+ defaultModel?: string;
241
+ /** Default max iterations */
242
+ defaultMaxIterations?: number;
243
+ }
244
+
245
+ /**
246
+ * Credential and identity type definitions
247
+ */
248
+ type AuthMethod = 'email' | 'web3_evm' | 'web3_solana' | 'web3_bitcoin' | 'web3_cosmos' | 'oauth_google' | 'oauth_github' | 'oauth_discord' | 'oauth_twitter';
249
+ type Web3Chain = 'ethereum' | 'solana' | 'bitcoin' | 'cosmos' | 'polygon' | 'arbitrum' | 'base';
250
+ type CredentialType = 'email' | 'web3_wallet' | 'oauth_social' | 'billing_stripe' | 'stripe_connect';
251
+ interface StackCredential {
252
+ id: string;
253
+ stack_identity_id: string;
254
+ credential_type: CredentialType;
255
+ credential_data: EmailCredentialData | Web3CredentialData | OAuthCredentialData | BillingCredentialData | StripeConnectCredentialData;
256
+ is_primary: boolean;
257
+ linked_at: number;
258
+ }
259
+ interface EmailCredentialData {
260
+ email_hash: string;
261
+ verified: boolean;
262
+ verified_at?: number;
263
+ }
264
+ interface Web3CredentialData {
265
+ chain: Web3Chain;
266
+ address: string;
267
+ address_type: 'p2wpkh' | 'p2tr' | 'ed25519' | 'secp256k1';
268
+ verification_signature: string;
269
+ verified_at: number;
270
+ }
271
+ interface OAuthCredentialData {
272
+ provider: 'google' | 'github' | 'discord' | 'twitter';
273
+ provider_user_id: string;
274
+ handle?: string;
275
+ verified_at: number;
276
+ }
277
+ interface BillingCredentialData {
278
+ provider: 'stripe';
279
+ customer_id: string;
280
+ has_payment_method: boolean;
281
+ default_payment_method_id?: string;
282
+ card_last_four?: string;
283
+ card_brand?: string;
284
+ billing_email?: string;
285
+ verified_at: number;
286
+ }
287
+ interface StripeConnectCredentialData {
288
+ provider: 'stripe_connect';
289
+ account_id: string;
290
+ details_submitted: boolean;
291
+ charges_enabled: boolean;
292
+ payouts_enabled: boolean;
293
+ email?: string;
294
+ verified_at: number;
295
+ }
296
+ interface CredentialLinkProof {
297
+ chain?: Web3Chain;
298
+ message?: string;
299
+ signature?: string;
300
+ public_key?: string;
301
+ provider?: string;
302
+ code?: string;
303
+ email?: string;
304
+ }
305
+ interface GlobalIdentity {
306
+ id: string;
307
+ identity_commitment: string;
308
+ root_public_key: string;
309
+ recovery_commitments: string[];
310
+ created_at: number;
311
+ updated_at: number;
312
+ }
313
+ interface StackIdentity {
314
+ id: string;
315
+ global_identity_id: string;
316
+ stack_id: string;
317
+ stack_public_key: string;
318
+ created_at: number;
319
+ last_login: number;
320
+ }
321
+ interface Session {
322
+ id: string;
323
+ app_identity_id: string;
324
+ global_identity_commitment: string;
325
+ app_id: string;
326
+ credentials: string[];
327
+ app_pubkey: string;
328
+ jwt: string;
329
+ issued_at: number;
330
+ expires_at: number;
331
+ issuer: string;
332
+ signed_by: string[];
333
+ }
334
+
335
+ export type { AuthMethod, BillingCredentialData, CoderClientConfig, CoderCommandInput, CoderCommandResult, CoderDiffInput, CoderExecuteRequest, CoderExecuteResponse, CoderFileContent, CoderFileInfo, CoderFileWriteInput, CoderFilesResponse, CoderMetrics, CoderProgressEvent, CoderSandbox, CoderSandboxConfig, CoderSandboxCreateInput, CoderSandboxExecInput, CoderSandboxExecResult, CoderSandboxResponse, CoderSearchResult, CoderSession, CoderSessionResponse, CoderSessionStatus, CoderSessionsListResponse, CoderStreamEvent, CoderStreamEventType, CoderThinkingEvent, CoderTool, CoderToolCallEvent, CoderToolParameter, CoderToolResult, CoderToolResultEvent, CoderToolsResponse, CredentialLinkProof, CredentialType, EmailCredentialData, GlobalIdentity, OAuthCredentialData, Session, StackCredential, StackIdentity, StripeConnectCredentialData, Web3Chain, Web3CredentialData };