@deepagents/experimental 6.1.2 → 7.0.1

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 (131) hide show
  1. package/README.md +151 -10
  2. package/dist/coding-agent-reminders/types.d.ts.map +1 -1
  3. package/dist/index.js +3975 -2519
  4. package/dist/index.js.map +4 -4
  5. package/dist/providers/claude/index.d.ts +4 -0
  6. package/dist/providers/claude/index.d.ts.map +1 -0
  7. package/dist/providers/claude/index.js +196 -0
  8. package/dist/providers/claude/index.js.map +7 -0
  9. package/dist/providers/claude/local-credentials.d.ts +3 -0
  10. package/dist/providers/claude/local-credentials.d.ts.map +1 -0
  11. package/dist/providers/codex/generate-via-stream.d.ts +8 -0
  12. package/dist/providers/codex/generate-via-stream.d.ts.map +1 -0
  13. package/dist/providers/codex/index.d.ts +4 -0
  14. package/dist/providers/codex/index.d.ts.map +1 -0
  15. package/dist/providers/codex/index.js +358 -0
  16. package/dist/providers/codex/index.js.map +7 -0
  17. package/dist/providers/codex/local-credentials.d.ts +4 -0
  18. package/dist/providers/codex/local-credentials.d.ts.map +1 -0
  19. package/dist/providers/language-model-provider.d.ts +5 -0
  20. package/dist/providers/language-model-provider.d.ts.map +1 -0
  21. package/dist/zukhruf/agent.d.ts +17 -2
  22. package/dist/zukhruf/agent.d.ts.map +1 -1
  23. package/dist/zukhruf/collaboration/agent-tool-context.d.ts +2 -2
  24. package/dist/zukhruf/collaboration/agent-tool-context.d.ts.map +1 -1
  25. package/dist/zukhruf/collaboration/collaboration-tools.d.ts +1807 -3
  26. package/dist/zukhruf/collaboration/collaboration-tools.d.ts.map +1 -1
  27. package/dist/zukhruf/collaboration/spawn-agent.d.ts.map +1 -1
  28. package/dist/zukhruf/collaboration/wait-agent.d.ts.map +1 -1
  29. package/dist/zukhruf/control-plane/agent-control-plane.d.ts +6 -7
  30. package/dist/zukhruf/control-plane/agent-control-plane.d.ts.map +1 -1
  31. package/dist/zukhruf/control-plane/agent-status-projector.d.ts +6 -3
  32. package/dist/zukhruf/control-plane/agent-status-projector.d.ts.map +1 -1
  33. package/dist/zukhruf/control-plane/agent-thread.d.ts.map +1 -1
  34. package/dist/zukhruf/index.d.ts +7 -4
  35. package/dist/zukhruf/index.d.ts.map +1 -1
  36. package/dist/zukhruf/index.js +4184 -2728
  37. package/dist/zukhruf/index.js.map +4 -4
  38. package/dist/zukhruf/{multi-agent-v2-config.d.ts → multi-agent-config.d.ts} +14 -9
  39. package/dist/zukhruf/multi-agent-config.d.ts.map +1 -0
  40. package/dist/zukhruf/plugins/conversation-scheduling/conversation-scheduler.d.ts +76 -0
  41. package/dist/zukhruf/plugins/conversation-scheduling/conversation-scheduler.d.ts.map +1 -0
  42. package/dist/zukhruf/plugins/conversation-scheduling/index.d.ts +13 -0
  43. package/dist/zukhruf/plugins/conversation-scheduling/index.d.ts.map +1 -0
  44. package/dist/zukhruf/plugins/conversation-scheduling/index.js +999 -0
  45. package/dist/zukhruf/plugins/conversation-scheduling/index.js.map +7 -0
  46. package/dist/zukhruf/plugins/conversation-scheduling/pg-boss.wake-scheduler.d.ts +19 -0
  47. package/dist/zukhruf/plugins/conversation-scheduling/pg-boss.wake-scheduler.d.ts.map +1 -0
  48. package/dist/zukhruf/plugins/conversation-scheduling/tools.d.ts +1305 -0
  49. package/dist/zukhruf/plugins/conversation-scheduling/tools.d.ts.map +1 -0
  50. package/dist/zukhruf/plugins/conversation-scheduling/wake-scheduler.d.ts +12 -0
  51. package/dist/zukhruf/plugins/conversation-scheduling/wake-scheduler.d.ts.map +1 -0
  52. package/dist/zukhruf/plugins/http/index.d.ts +50 -0
  53. package/dist/zukhruf/plugins/http/index.d.ts.map +1 -0
  54. package/dist/zukhruf/plugins/http/index.js +618 -0
  55. package/dist/zukhruf/plugins/http/index.js.map +7 -0
  56. package/dist/zukhruf/plugins/http/parse.d.ts.map +1 -0
  57. package/dist/zukhruf/plugins/http/validator.d.ts.map +1 -0
  58. package/dist/zukhruf/plugins/mcp/index.d.ts +8 -0
  59. package/dist/zukhruf/plugins/mcp/index.d.ts.map +1 -0
  60. package/dist/zukhruf/plugins/mcp/index.js +25 -0
  61. package/dist/zukhruf/plugins/mcp/index.js.map +7 -0
  62. package/dist/zukhruf/plugins/schedules/http.d.ts +45 -0
  63. package/dist/zukhruf/plugins/schedules/http.d.ts.map +1 -0
  64. package/dist/zukhruf/plugins/schedules/http.js +528 -0
  65. package/dist/zukhruf/plugins/schedules/http.js.map +7 -0
  66. package/dist/zukhruf/plugins/schedules/index.d.ts +35 -0
  67. package/dist/zukhruf/plugins/schedules/index.d.ts.map +1 -0
  68. package/dist/zukhruf/plugins/schedules/index.js +1873 -0
  69. package/dist/zukhruf/plugins/schedules/index.js.map +7 -0
  70. package/dist/zukhruf/plugins/schedules/schedule-files.d.ts +6 -0
  71. package/dist/zukhruf/plugins/schedules/schedule-files.d.ts.map +1 -0
  72. package/dist/zukhruf/plugins/schedules/scheduled-tasks.d.ts +157 -0
  73. package/dist/zukhruf/plugins/schedules/scheduled-tasks.d.ts.map +1 -0
  74. package/dist/zukhruf/plugins/uploads/http.d.ts +27 -0
  75. package/dist/zukhruf/plugins/uploads/http.d.ts.map +1 -0
  76. package/dist/zukhruf/plugins/uploads/http.js +426 -0
  77. package/dist/zukhruf/plugins/uploads/http.js.map +7 -0
  78. package/dist/zukhruf/plugins/uploads/index.d.ts +73 -0
  79. package/dist/zukhruf/plugins/uploads/index.d.ts.map +1 -0
  80. package/dist/zukhruf/plugins/uploads/index.js +247 -0
  81. package/dist/zukhruf/plugins/uploads/index.js.map +7 -0
  82. package/dist/zukhruf/queue/pg-boss-notifications.d.ts +10 -0
  83. package/dist/zukhruf/queue/pg-boss-notifications.d.ts.map +1 -0
  84. package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts +8 -11
  85. package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts.map +1 -1
  86. package/dist/zukhruf/queue/turn-queue.d.ts +43 -38
  87. package/dist/zukhruf/queue/turn-queue.d.ts.map +1 -1
  88. package/dist/zukhruf/runtime/agent-runtime.d.ts +148 -43
  89. package/dist/zukhruf/runtime/agent-runtime.d.ts.map +1 -1
  90. package/dist/zukhruf/runtime/agent-turn-executor.d.ts +9 -2
  91. package/dist/zukhruf/runtime/agent-turn-executor.d.ts.map +1 -1
  92. package/dist/zukhruf/runtime/approval-controller.d.ts +10 -25
  93. package/dist/zukhruf/runtime/approval-controller.d.ts.map +1 -1
  94. package/dist/zukhruf/runtime/compaction.d.ts +47 -0
  95. package/dist/zukhruf/runtime/compaction.d.ts.map +1 -0
  96. package/dist/zukhruf/runtime/conversation-status/change-source.d.ts +19 -0
  97. package/dist/zukhruf/runtime/conversation-status/change-source.d.ts.map +1 -0
  98. package/dist/zukhruf/runtime/conversation-status/child-progress.d.ts +84 -0
  99. package/dist/zukhruf/runtime/conversation-status/child-progress.d.ts.map +1 -0
  100. package/dist/zukhruf/runtime/conversation-status/pg-boss-change-source.d.ts +22 -0
  101. package/dist/zukhruf/runtime/conversation-status/pg-boss-change-source.d.ts.map +1 -0
  102. package/dist/zukhruf/runtime/conversation-status/projector.d.ts +62 -0
  103. package/dist/zukhruf/runtime/conversation-status/projector.d.ts.map +1 -0
  104. package/dist/zukhruf/runtime/conversation-status/status-publishing-turn-queue.d.ts +20 -0
  105. package/dist/zukhruf/runtime/conversation-status/status-publishing-turn-queue.d.ts.map +1 -0
  106. package/dist/zukhruf/runtime/plugin/agent-skills.d.ts +22 -0
  107. package/dist/zukhruf/runtime/plugin/agent-skills.d.ts.map +1 -0
  108. package/dist/zukhruf/runtime/plugin/plugin-agents.d.ts +14 -0
  109. package/dist/zukhruf/runtime/plugin/plugin-agents.d.ts.map +1 -0
  110. package/dist/zukhruf/runtime/plugin/plugin-bindings.d.ts +8 -0
  111. package/dist/zukhruf/runtime/plugin/plugin-bindings.d.ts.map +1 -0
  112. package/dist/zukhruf/runtime/plugin/plugin-context-composition.d.ts +7 -0
  113. package/dist/zukhruf/runtime/plugin/plugin-context-composition.d.ts.map +1 -0
  114. package/dist/zukhruf/runtime/plugin/plugin-manager.d.ts +38 -0
  115. package/dist/zukhruf/runtime/plugin/plugin-manager.d.ts.map +1 -0
  116. package/dist/zukhruf/runtime/plugin/plugin-tool-composition.d.ts +10 -0
  117. package/dist/zukhruf/runtime/plugin/plugin-tool-composition.d.ts.map +1 -0
  118. package/dist/zukhruf/tool.d.ts +5 -1
  119. package/dist/zukhruf/tool.d.ts.map +1 -1
  120. package/package.json +72 -6
  121. package/dist/zukhruf/multi-agent-v2-config.d.ts.map +0 -1
  122. package/dist/zukhruf/protocol/parse.d.ts.map +0 -1
  123. package/dist/zukhruf/protocol/session.d.ts +0 -23
  124. package/dist/zukhruf/protocol/session.d.ts.map +0 -1
  125. package/dist/zukhruf/protocol/validator.d.ts.map +0 -1
  126. package/dist/zukhruf/runtime/agent-skills.d.ts +0 -9
  127. package/dist/zukhruf/runtime/agent-skills.d.ts.map +0 -1
  128. package/dist/zukhruf/runtime/approval-job-id.d.ts +0 -3
  129. package/dist/zukhruf/runtime/approval-job-id.d.ts.map +0 -1
  130. /package/dist/zukhruf/{protocol → plugins/http}/parse.d.ts +0 -0
  131. /package/dist/zukhruf/{protocol → plugins/http}/validator.d.ts +0 -0
@@ -0,0 +1,6 @@
1
+ import type { ScheduleSource } from './index.ts';
2
+ export declare function scheduleFiles({ directory, ownerId, }: {
3
+ directory: string | URL;
4
+ ownerId: string;
5
+ }): ScheduleSource;
6
+ //# sourceMappingURL=schedule-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule-files.d.ts","sourceRoot":"","sources":["../../../../src/zukhruf/plugins/schedules/schedule-files.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,YAAY,CAAC;AAWlE,wBAAgB,aAAa,CAAC,EAC5B,SAAS,EACT,OAAO,GACR,EAAE;IACD,SAAS,EAAE,MAAM,GAAG,GAAG,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,cAAc,CAEjB"}
@@ -0,0 +1,157 @@
1
+ import type { Db, JobPollingOptions, PgBoss, Queue } from 'pg-boss';
2
+ export declare const SCHEDULE_CHANGES_CHANNEL = "zukhruf_schedule_changes";
3
+ export type ScheduledTaskStatus = 'active' | 'paused' | 'completed' | 'archived';
4
+ export type ScheduledRunStatus = 'dispatching' | 'running' | 'completed' | 'failed' | 'cancelled';
5
+ export type ScheduledRunReviewStatus = 'pending_review' | 'reviewed' | 'archived';
6
+ export type ScheduledTasksErrorCode = 'invalid-input' | 'not-found' | 'conflict';
7
+ export type ScheduledTasksResource = 'task' | 'run';
8
+ /** Domain rejection a transport can categorise without matching messages. */
9
+ export declare class ScheduledTasksError extends Error {
10
+ readonly name = "ScheduledTasksError";
11
+ readonly code: ScheduledTasksErrorCode;
12
+ readonly resource: ScheduledTasksResource;
13
+ constructor(code: ScheduledTasksErrorCode, resource: ScheduledTasksResource, message: string, options?: ErrorOptions);
14
+ }
15
+ export interface ScheduledTask<ExecutionConfig extends object> {
16
+ id: string;
17
+ ownerId: string;
18
+ idempotencyKey: string;
19
+ name: string;
20
+ prompt: string;
21
+ recurrence: string;
22
+ timezone: string;
23
+ executionConfig: ExecutionConfig;
24
+ status: ScheduledTaskStatus;
25
+ generation: number;
26
+ nextRunAt: number | null;
27
+ createdAt: number;
28
+ updatedAt: number;
29
+ archivedAt: number | null;
30
+ }
31
+ export interface ScheduledRun<ExecutionConfig extends object> {
32
+ id: string;
33
+ taskId: string;
34
+ ownerId: string;
35
+ trigger: 'scheduled' | 'manual';
36
+ occurrenceAt: number;
37
+ prompt: string;
38
+ executionConfig: ExecutionConfig;
39
+ status: ScheduledRunStatus;
40
+ reviewStatus: ScheduledRunReviewStatus | null;
41
+ externalExecutionId: string | null;
42
+ startedAt: number | null;
43
+ finishedAt: number | null;
44
+ title: string | null;
45
+ summary: string | null;
46
+ error: string | null;
47
+ createdAt: number;
48
+ updatedAt: number;
49
+ }
50
+ export type ScheduledExecutionObservation = {
51
+ status: 'queued';
52
+ startedAt: number | null;
53
+ } | {
54
+ status: 'running';
55
+ startedAt: number | null;
56
+ } | {
57
+ status: 'completed' | 'failed' | 'cancelled';
58
+ startedAt: number | null;
59
+ finishedAt: number;
60
+ error: string | null;
61
+ title: string | null;
62
+ summary: string | null;
63
+ };
64
+ export interface ScheduledExecutionAdapter<ExecutionConfig extends object> {
65
+ /** Repeated calls with the same run ID must return the same execution. */
66
+ launch(input: {
67
+ runId: string;
68
+ taskId: string;
69
+ ownerId: string;
70
+ trigger: 'scheduled' | 'manual';
71
+ occurrenceAt: number;
72
+ prompt: string;
73
+ executionConfig: ExecutionConfig;
74
+ }): Promise<{
75
+ executionId: string;
76
+ }>;
77
+ inspect(input: {
78
+ runId: string;
79
+ ownerId: string;
80
+ executionId: string;
81
+ executionConfig: ExecutionConfig;
82
+ }): Promise<ScheduledExecutionObservation>;
83
+ /** Cancellation must be safe to repeat. */
84
+ cancel(input: {
85
+ runId: string;
86
+ ownerId: string;
87
+ executionId: string;
88
+ executionConfig: ExecutionConfig;
89
+ }): Promise<void>;
90
+ }
91
+ export interface CreateScheduledTaskInput<ExecutionConfig extends object> {
92
+ idempotencyKey: string;
93
+ name: string;
94
+ prompt: string;
95
+ recurrence: string;
96
+ timezone: string;
97
+ executionConfig: ExecutionConfig;
98
+ }
99
+ export interface UpdateScheduledTaskInput<ExecutionConfig extends object> {
100
+ name?: string;
101
+ prompt?: string;
102
+ recurrence?: string;
103
+ timezone?: string;
104
+ executionConfig?: ExecutionConfig;
105
+ }
106
+ export type ScheduledChange = {
107
+ type: 'reset';
108
+ } | {
109
+ type: 'change';
110
+ resource: 'schedule-task';
111
+ id: string;
112
+ } | {
113
+ type: 'change';
114
+ resource: 'schedule-run';
115
+ id: string;
116
+ taskId: string;
117
+ };
118
+ export interface ScheduledTaskTransaction {
119
+ <T>(operation: (database: Db) => Promise<T>): Promise<T>;
120
+ }
121
+ export interface ScheduledTasksOptions<ExecutionConfig extends object> {
122
+ boss: PgBoss;
123
+ queue: string;
124
+ queueOptions?: Omit<Queue, 'name'>;
125
+ reconciliationIntervalMs: number;
126
+ transaction: ScheduledTaskTransaction;
127
+ executor: ScheduledExecutionAdapter<ExecutionConfig>;
128
+ }
129
+ /** Durable Scheduled Tasks implementation backed by PostgreSQL and pg-boss. */
130
+ export declare class ScheduledTasks<ExecutionConfig extends object> {
131
+ #private;
132
+ constructor(options: ScheduledTasksOptions<ExecutionConfig>);
133
+ initialize(): Promise<void>;
134
+ subscribeChanges(ownerId: string, signal: AbortSignal): Promise<AsyncIterable<ScheduledChange>>;
135
+ create(ownerId: string, input: CreateScheduledTaskInput<ExecutionConfig>): Promise<ScheduledTask<ExecutionConfig>>;
136
+ get(ownerId: string, taskId: string): Promise<ScheduledTask<ExecutionConfig>>;
137
+ list(ownerId: string): Promise<ScheduledTask<ExecutionConfig>[]>;
138
+ listRuns(ownerId: string, taskId: string): Promise<ScheduledRun<ExecutionConfig>[]>;
139
+ getRun(ownerId: string, runId: string): Promise<ScheduledRun<ExecutionConfig>>;
140
+ /**
141
+ * Owner-wide review queue. `review_status` is only written when a run reaches
142
+ * a terminal state, so pending runs are exactly the unreviewed terminal ones,
143
+ * including runs whose task has since been archived.
144
+ */
145
+ listPendingReview(ownerId: string): Promise<ScheduledRun<ExecutionConfig>[]>;
146
+ pause(ownerId: string, taskId: string): Promise<ScheduledTask<ExecutionConfig>>;
147
+ resume(ownerId: string, taskId: string): Promise<ScheduledTask<ExecutionConfig>>;
148
+ update(ownerId: string, taskId: string, input: UpdateScheduledTaskInput<ExecutionConfig>): Promise<ScheduledTask<ExecutionConfig>>;
149
+ runNow(ownerId: string, taskId: string, idempotencyKey: string): Promise<ScheduledRun<ExecutionConfig>>;
150
+ archive(ownerId: string, taskId: string): Promise<ScheduledTask<ExecutionConfig>>;
151
+ purge(ownerId: string, taskId: string): Promise<void>;
152
+ cancelRun(ownerId: string, runId: string): Promise<ScheduledRun<ExecutionConfig>>;
153
+ markReviewed(ownerId: string, runId: string): Promise<ScheduledRun<ExecutionConfig>>;
154
+ archiveRun(ownerId: string, runId: string): Promise<ScheduledRun<ExecutionConfig>>;
155
+ work(options?: JobPollingOptions, waitForActive?: boolean): Promise<AsyncDisposable>;
156
+ }
157
+ //# sourceMappingURL=scheduled-tasks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduled-tasks.d.ts","sourceRoot":"","sources":["../../../../src/zukhruf/plugins/schedules/scheduled-tasks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,EAAE,EACF,iBAAiB,EAEjB,MAAM,EACN,KAAK,EACN,MAAM,SAAS,CAAC;AAOjB,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AAsGnE,MAAM,MAAM,mBAAmB,GAC7B,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAC;AACjD,MAAM,MAAM,kBAAkB,GAC5B,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;AACnE,MAAM,MAAM,wBAAwB,GAClC,gBAAgB,GAAG,UAAU,GAAG,UAAU,CAAC;AAE7C,MAAM,MAAM,uBAAuB,GACjC,eAAe,GAAG,WAAW,GAAG,UAAU,CAAC;AAC7C,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,KAAK,CAAC;AAEpD,6EAA6E;AAC7E,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAkB,IAAI,yBAAyB;IAC/C,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IACvC,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,CAAC;gBAGxC,IAAI,EAAE,uBAAuB,EAC7B,QAAQ,EAAE,sBAAsB,EAChC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,YAAY;CAMzB;AAED,MAAM,WAAW,aAAa,CAAC,eAAe,SAAS,MAAM;IAC3D,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE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AAY,CAAC,eAAe,CAAC,CAAC;IAmDnC,OAAO,CACX,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;IAqBpC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA4CrD,SAAS,CACb,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAiDnC,YAAY,CAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAInC,UAAU,CACd,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAInC,IAAI,CACR,OAAO,CAAC,EAAE,iBAAiB,EAC3B,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,eAAe,CAAC;CAof5B"}
@@ -0,0 +1,27 @@
1
+ import type { AgentPluginDefinition } from '../../runtime/agent-runtime.ts';
2
+ import { type HttpProjection } from '../http/index.ts';
3
+ import { type UploadMediaType, type Uploads } from './index.ts';
4
+ export declare const UPLOAD_FILENAME_HEADER = "x-upload-filename";
5
+ /**
6
+ * What `POST /session/:sessionId/uploads` answers. The composer keeps it and
7
+ * sends it back under `message.metadata.uploads` on the turn that attaches it.
8
+ */
9
+ export interface UploadReceipt {
10
+ /** Absolute sandbox path the model reads with the sandbox read tool. */
11
+ path: string;
12
+ /** Client file name from the `x-upload-filename` header. */
13
+ name: string;
14
+ mediaType: UploadMediaType;
15
+ /** Byte length of the stored file. */
16
+ size: number;
17
+ /** `GET` route serving the bytes for rendering. */
18
+ url: string;
19
+ }
20
+ /**
21
+ * Per-session upload and retrieval bound to one `uploads()` definition.
22
+ * The caller must choose the maximum accepted upload size in bytes.
23
+ */
24
+ export declare function uploadsHttp(definition: AgentPluginDefinition<Uploads>, { maxBytes }: {
25
+ maxBytes: number;
26
+ }): HttpProjection;
27
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../src/zukhruf/plugins/uploads/http.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,OAAO,EAEb,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,sBAAsB,sBAAsB,CAAC;AAwB1D;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,eAAe,CAAC;IAC3B,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,UAAU,EAAE,qBAAqB,CAAC,OAAO,CAAC,EAC1C,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GACjC,cAAc,CAYhB"}
@@ -0,0 +1,426 @@
1
+ // packages/experimental/src/zukhruf/plugins/uploads/http.ts
2
+ import { safeParse as parseContentType2 } from "fast-content-type-parse";
3
+ import { Hono as Hono2 } from "hono";
4
+ import { bodyLimit } from "hono/body-limit";
5
+ import { HTTPException as HTTPException4 } from "hono/http-exception";
6
+ import z5 from "zod";
7
+
8
+ // packages/experimental/src/zukhruf/plugins/http/index.ts
9
+ import {
10
+ createUIMessageStreamResponse,
11
+ safeValidateUIMessages
12
+ } from "ai";
13
+ import { Hono } from "hono";
14
+ import { HTTPException as HTTPException3 } from "hono/http-exception";
15
+ import { basePath } from "hono/route";
16
+ import { streamSSE } from "hono/streaming";
17
+ import { validate as validateUuid } from "uuid";
18
+ import z3 from "zod";
19
+ import { elementsSchema } from "@deepagents/elements";
20
+
21
+ // packages/experimental/src/zukhruf/plugins/http/validator.ts
22
+ import { parse as parseContentType } from "fast-content-type-parse";
23
+ import { createMiddleware } from "hono/factory";
24
+ import { HTTPException as HTTPException2 } from "hono/http-exception";
25
+ import z2 from "zod";
26
+
27
+ // packages/experimental/src/zukhruf/plugins/http/parse.ts
28
+ import { HTTPException } from "hono/http-exception";
29
+ import "zod";
30
+ async function parse(schema, input) {
31
+ const result = await schema.safeParseAsync(input);
32
+ if (!result.success) {
33
+ const errors = result.error.flatten((issue) => ({
34
+ message: issue.message,
35
+ code: issue.code,
36
+ path: issue.path.join(".")
37
+ })).fieldErrors;
38
+ throw new HTTPException(400, {
39
+ message: "Validation failed",
40
+ cause: {
41
+ code: "api/validation-failed",
42
+ detail: "The input data is invalid",
43
+ errors
44
+ }
45
+ });
46
+ }
47
+ return result.data;
48
+ }
49
+
50
+ // packages/experimental/src/zukhruf/plugins/http/validator.ts
51
+ function validate(expectedContentTypeOrSelector, selector) {
52
+ const expectedContentType = typeof expectedContentTypeOrSelector === "string" ? expectedContentTypeOrSelector : void 0;
53
+ const _selector = typeof expectedContentTypeOrSelector === "function" ? expectedContentTypeOrSelector : selector;
54
+ void _selector;
55
+ if (!_selector) {
56
+ throw new Error("Selector function is required");
57
+ }
58
+ return createMiddleware(async (c, next) => {
59
+ const ct = c.req.header("content-type");
60
+ if (c.req.method === "GET" && ct) {
61
+ throw new HTTPException2(415, {
62
+ message: "Unsupported Media Type",
63
+ cause: {
64
+ code: "api/unsupported-media-type",
65
+ detail: `GET requests cannot have a content type header`
66
+ }
67
+ });
68
+ }
69
+ if (expectedContentType) {
70
+ void verifyContentType(ct, expectedContentType);
71
+ }
72
+ const contentType = ct ? parseContentType(ct) : null;
73
+ let body = null;
74
+ switch (contentType?.type) {
75
+ case "application/json":
76
+ body = await parseJson(c);
77
+ break;
78
+ case "application/x-www-form-urlencoded":
79
+ case "multipart/form-data":
80
+ body = await c.req.parseBody();
81
+ break;
82
+ default:
83
+ body = {};
84
+ }
85
+ const payload = {
86
+ body,
87
+ query: parseQueryParams(c.req.query()),
88
+ queries: parseQueriesParams(c.req.queries()),
89
+ params: c.req.param(),
90
+ headers: c.req.header()
91
+ };
92
+ const config = _selector(payload);
93
+ const schema = z2.object(
94
+ Object.entries(config).reduce(
95
+ (acc, [key, value]) => {
96
+ acc[key] = value.against;
97
+ return acc;
98
+ },
99
+ {}
100
+ )
101
+ );
102
+ const input = Object.entries(config).reduce(
103
+ (acc, [key, value]) => {
104
+ acc[key] = value.select;
105
+ return acc;
106
+ },
107
+ {}
108
+ );
109
+ const parsed = await parse(schema, input);
110
+ c.set("input", parsed);
111
+ await next();
112
+ });
113
+ }
114
+ function verifyContentType(actual, expected) {
115
+ if (!actual) {
116
+ throw new HTTPException2(415, {
117
+ message: "Unsupported Media Type",
118
+ cause: {
119
+ code: "api/unsupported-media-type",
120
+ detail: "Missing content type header"
121
+ }
122
+ });
123
+ }
124
+ const { type: incomingContentType } = parseContentType(actual);
125
+ if (incomingContentType !== expected) {
126
+ throw new HTTPException2(415, {
127
+ message: "Unsupported Media Type",
128
+ cause: {
129
+ code: "api/unsupported-media-type",
130
+ detail: `Expected content type: ${expected}, but got: ${incomingContentType}`
131
+ }
132
+ });
133
+ }
134
+ }
135
+ async function parseJson(context) {
136
+ try {
137
+ return await context.req.json();
138
+ } catch (error) {
139
+ throw new HTTPException2(400, {
140
+ message: "The request body is not valid JSON",
141
+ cause: {
142
+ code: "api/invalid-json",
143
+ detail: error instanceof Error ? error.message : String(error)
144
+ }
145
+ });
146
+ }
147
+ }
148
+ function parseQueryParams(queryParams) {
149
+ return Object.fromEntries(
150
+ Object.entries(queryParams).map(([key, value]) => [
151
+ key,
152
+ value === "null" ? null : value
153
+ ])
154
+ );
155
+ }
156
+ function parseQueriesParams(queriesParams) {
157
+ return Object.fromEntries(
158
+ Object.entries(queriesParams).map(([key, values]) => [
159
+ key,
160
+ values.map((value) => value === "null" ? null : value)
161
+ ])
162
+ );
163
+ }
164
+
165
+ // packages/experimental/src/zukhruf/plugins/http/index.ts
166
+ function projectHttp(definition, project) {
167
+ return {
168
+ project(runtime) {
169
+ return project(runtime.plugin(definition), runtime);
170
+ }
171
+ };
172
+ }
173
+ function mountPath(context) {
174
+ return basePath(context).replace(/\/$/, "");
175
+ }
176
+ var sessionIdSchema = z3.string().refine(validateUuid);
177
+ var jsonSchema = z3.custom(
178
+ (value) => typeof value === "object" && value !== null && !Array.isArray(value)
179
+ );
180
+ var clientToolsSchema = z3.record(
181
+ z3.string().min(1),
182
+ z3.strictObject({
183
+ inputSchema: jsonSchema,
184
+ description: z3.string().min(1)
185
+ })
186
+ ).optional();
187
+ var turnBodySchema = z3.strictObject({
188
+ sessionId: sessionIdSchema,
189
+ message: z3.unknown(),
190
+ trigger: z3.enum(["submit-message", "regenerate-message"]),
191
+ tools: clientToolsSchema,
192
+ elements: elementsSchema
193
+ });
194
+
195
+ // packages/experimental/src/zukhruf/plugins/uploads/index.ts
196
+ import { tool } from "ai";
197
+ import z4 from "zod";
198
+ import { reminder } from "@deepagents/context";
199
+ var extensionByMediaType = {
200
+ "image/png": "png",
201
+ "image/jpeg": "jpg",
202
+ "image/webp": "webp",
203
+ "image/gif": "gif",
204
+ "image/heic": "heic",
205
+ "image/heif": "heif",
206
+ "video/mp4": "mp4",
207
+ "video/quicktime": "mov",
208
+ "audio/mpeg": "mp3",
209
+ "audio/mp4": "m4a",
210
+ "audio/wav": "wav"
211
+ };
212
+ var UPLOAD_MEDIA_TYPES = Object.keys(
213
+ extensionByMediaType
214
+ );
215
+ var mediaTypeByExtension = {
216
+ ...Object.fromEntries(
217
+ Object.entries(extensionByMediaType).map(([mediaType, extension]) => [
218
+ extension,
219
+ mediaType
220
+ ])
221
+ ),
222
+ jpeg: "image/jpeg"
223
+ };
224
+ var UPLOAD_FILE_ID_PATTERN = new RegExp(
225
+ `^[0-9a-f-]{36}\\.(${Object.keys(mediaTypeByExtension).join("|")})$`
226
+ );
227
+ function isUploadMediaType(mediaType) {
228
+ return Object.hasOwn(extensionByMediaType, mediaType);
229
+ }
230
+ var publishInputSchema = z4.object({
231
+ path: z4.string().startsWith("/").describe(
232
+ "Absolute sandbox path of the file to publish; it must be inside this session's uploads directory (the directory the attached files live in, subdirectories included)."
233
+ ),
234
+ name: z4.string().min(1).optional().describe("Display name shown to the user; defaults to the file name.")
235
+ });
236
+
237
+ // packages/experimental/src/zukhruf/plugins/uploads/http.ts
238
+ var UPLOAD_FILENAME_HEADER = "x-upload-filename";
239
+ var SESSION_UPLOADS_ROUTE_PATH = "/session/:sessionId/uploads";
240
+ var SESSION_UPLOAD_ROUTE_PATH = `${SESSION_UPLOADS_ROUTE_PATH}/:fileId`;
241
+ var NO_STORE = { "cache-control": "no-store" };
242
+ var IMMUTABLE = {
243
+ "cache-control": "private, max-age=31536000, immutable"
244
+ };
245
+ var sessionIdSchema2 = z5.uuid();
246
+ var uploadFilenameSchema = z5.string().min(1).transform((encoded, context) => {
247
+ try {
248
+ return decodeURIComponent(encoded);
249
+ } catch {
250
+ context.addIssue({
251
+ code: "custom",
252
+ message: `${UPLOAD_FILENAME_HEADER} must be URI-encoded`
253
+ });
254
+ return z5.NEVER;
255
+ }
256
+ });
257
+ function uploadsHttp(definition, { maxBytes }) {
258
+ if (!Number.isSafeInteger(maxBytes) || maxBytes <= 0) {
259
+ throw new TypeError(
260
+ "uploadsHttp: maxBytes must be a positive safe integer"
261
+ );
262
+ }
263
+ return projectHttp(definition, (plugin) => ({
264
+ capabilities: {
265
+ uploads: { path: "/session", mediaTypes: UPLOAD_MEDIA_TYPES }
266
+ },
267
+ authenticatedRoutes: uploadRoutes(plugin, maxBytes)
268
+ }));
269
+ }
270
+ function uploadRoutes(uploads, maxBytes) {
271
+ const app = new Hono2();
272
+ app.post(
273
+ SESSION_UPLOADS_ROUTE_PATH,
274
+ bodyLimit({
275
+ maxSize: maxBytes,
276
+ onError: () => {
277
+ throw new HTTPException4(413, {
278
+ message: "Upload is too large",
279
+ cause: {
280
+ code: "api/payload-too-large",
281
+ detail: `Upload exceeds ${maxBytes} bytes`
282
+ }
283
+ });
284
+ }
285
+ }),
286
+ validate((payload) => ({
287
+ sessionId: {
288
+ select: payload.params.sessionId,
289
+ against: sessionIdSchema2
290
+ },
291
+ name: {
292
+ select: payload.headers[UPLOAD_FILENAME_HEADER],
293
+ against: uploadFilenameSchema
294
+ }
295
+ })),
296
+ async (context) => {
297
+ const { sessionId, name } = context.var.input;
298
+ const contentType = context.req.header("content-type");
299
+ const mediaType = contentType === void 0 ? void 0 : parseContentType2(contentType).type;
300
+ if (mediaType === void 0 || !isUploadMediaType(mediaType)) {
301
+ throw new HTTPException4(415, {
302
+ message: "Unsupported Media Type",
303
+ cause: {
304
+ code: "zukhruf/unsupported-media-type",
305
+ detail: `Uploads must be one of ${UPLOAD_MEDIA_TYPES.join(", ")}`
306
+ }
307
+ });
308
+ }
309
+ const data = new Uint8Array(await context.req.arrayBuffer());
310
+ const { fileId, path } = await uploads.write(
311
+ { userId: context.get("userId"), sessionId },
312
+ { data, mediaType }
313
+ );
314
+ const url = new URL(
315
+ `${mountPath(context)}/session/${sessionId}/uploads/${fileId}`,
316
+ context.req.url
317
+ ).href;
318
+ return context.json(
319
+ {
320
+ path,
321
+ name,
322
+ mediaType,
323
+ size: data.byteLength,
324
+ url
325
+ },
326
+ 201,
327
+ NO_STORE
328
+ );
329
+ }
330
+ );
331
+ app.all(
332
+ SESSION_UPLOADS_ROUTE_PATH,
333
+ (context) => methodNotAllowed(context, "POST")
334
+ );
335
+ app.on(
336
+ ["GET", "HEAD"],
337
+ SESSION_UPLOAD_ROUTE_PATH,
338
+ validate((payload) => ({
339
+ sessionId: {
340
+ select: payload.params.sessionId,
341
+ against: sessionIdSchema2
342
+ }
343
+ })),
344
+ async (context) => {
345
+ const { sessionId } = context.var.input;
346
+ const fileId = context.req.param("fileId");
347
+ const upload = await uploads.read(
348
+ { userId: context.get("userId"), sessionId },
349
+ fileId
350
+ );
351
+ if (!upload) {
352
+ throw new HTTPException4(404, {
353
+ message: "Upload not found",
354
+ cause: {
355
+ code: "zukhruf/upload-not-found",
356
+ detail: `Upload ${fileId} does not exist in session ${sessionId}`
357
+ }
358
+ });
359
+ }
360
+ const total = upload.data.byteLength;
361
+ const headers = {
362
+ "content-type": upload.mediaType,
363
+ "accept-ranges": "bytes",
364
+ ...IMMUTABLE
365
+ };
366
+ const rangeHeader = context.req.header("range");
367
+ const head = context.req.method === "HEAD";
368
+ if (rangeHeader === void 0) {
369
+ const full = { ...headers, "content-length": String(total) };
370
+ return head ? context.body(null, 200, full) : context.body(upload.data, 200, full);
371
+ }
372
+ const range = parseByteRange(rangeHeader, total);
373
+ if (range === void 0) {
374
+ return context.body(null, 416, {
375
+ ...headers,
376
+ "content-range": `bytes */${total}`
377
+ });
378
+ }
379
+ const partial = {
380
+ ...headers,
381
+ "content-range": `bytes ${range.start}-${range.end}/${total}`,
382
+ "content-length": String(range.end - range.start + 1)
383
+ };
384
+ return head ? context.body(null, 206, partial) : context.body(
385
+ upload.data.subarray(range.start, range.end + 1),
386
+ 206,
387
+ partial
388
+ );
389
+ }
390
+ );
391
+ app.all(
392
+ SESSION_UPLOAD_ROUTE_PATH,
393
+ (context) => methodNotAllowed(context, "GET, HEAD")
394
+ );
395
+ return app;
396
+ }
397
+ function parseByteRange(header, total) {
398
+ const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
399
+ if (match === null || total === 0) return void 0;
400
+ const [, first, last] = match;
401
+ if (first === "" && last === "") return void 0;
402
+ if (first === "") {
403
+ const suffix = Number(last);
404
+ if (suffix === 0) return void 0;
405
+ return { start: Math.max(total - suffix, 0), end: total - 1 };
406
+ }
407
+ const start = Number(first);
408
+ const end = last === "" ? total - 1 : Math.min(Number(last), total - 1);
409
+ if (start > end || start >= total) return void 0;
410
+ return { start, end };
411
+ }
412
+ function methodNotAllowed(context, allow) {
413
+ context.header("Allow", allow);
414
+ throw new HTTPException4(405, {
415
+ message: "Method not allowed",
416
+ cause: {
417
+ code: "api/method-not-allowed",
418
+ detail: `This endpoint only accepts ${allow} requests`
419
+ }
420
+ });
421
+ }
422
+ export {
423
+ UPLOAD_FILENAME_HEADER,
424
+ uploadsHttp
425
+ };
426
+ //# sourceMappingURL=http.js.map