@ai-ecoverse/slicc-agent 7.25.1 → 7.26.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.
@@ -6,6 +6,7 @@ export interface SendAttachment {
6
6
  data?: string;
7
7
  text?: string;
8
8
  path?: string;
9
+ upload?: string;
9
10
  }
10
11
  export interface ShownAttachment {
11
12
  id: string;
@@ -28,16 +29,25 @@ export type Part = {
28
29
  export interface Saver {
29
30
  sees: boolean;
30
31
  save?(name: string, bytes: Uint8Array): Promise<string>;
32
+ staging?: {
33
+ take(id: string): Promise<Blob | undefined>;
34
+ drop(id: string): Promise<void>;
35
+ };
31
36
  }
32
37
  export declare const IMAGE_LIMIT: number;
38
+ export declare const INLINE_LIMIT: number;
39
+ export declare const INLINE_TOTAL: number;
33
40
  export declare const FILE_LIMIT: number;
34
41
  export declare const TOTAL_LIMIT: number;
42
+ export declare const STAGED_DIR = "/.slicc/attachments";
43
+ export declare const STAGED_ID: RegExp;
44
+ export declare function stagedDir(serverId: string): string;
35
45
  export declare const SEEN: Set<string>;
36
46
  export declare const BLIND = "This model can't see images, so the image was saved as a file instead.";
37
- export declare const TOGETHER = "These attachments add up to more than 10 MiB; send them in separate messages.";
47
+ export declare const UNSHOWN = "The image was too large to show the model, so it was saved as a file instead.";
38
48
  export declare function mib(bytes: number): string;
39
- export declare function limitOf(kind: AttachmentKind): number;
40
- export declare function tooLarge(name: string, kind: AttachmentKind): string;
49
+ export declare function together(limit: number): string;
50
+ export declare function tooLarge(name: string, limit: number): string;
41
51
  export declare function textBytes(text: string): number;
42
52
  export declare function decodedSize(data: string): number;
43
53
  export declare function fromBase64(data: string): Uint8Array;
@@ -35,6 +35,7 @@ export interface AgentWorkerOptions {
35
35
  users?: boolean;
36
36
  mcpRedirect?: string;
37
37
  approvalMs?: number;
38
+ stagedMs?: number;
38
39
  }
39
40
  export declare function usersOf(admin: MessagePort | undefined, wanted: boolean | undefined, attach: KernelAttach): UserClients | undefined;
40
41
  export declare const STORE_DIR = "/.slicc";
@@ -4,6 +4,7 @@ import { type VaultHold } from '../secrets/view.ts';
4
4
  import type { Command } from '../services.ts';
5
5
  import { Emitter } from './emitter.ts';
6
6
  import { type ShownImport } from './import-port.ts';
7
+ import { type AttachmentLimits } from './outgoing.ts';
7
8
  export declare const CONE = "cone";
8
9
  export declare const OLDER_PAGE = 100;
9
10
  export declare const OLDER_PAGES = 40;
@@ -22,6 +23,7 @@ export declare class AgentAdapter extends Emitter<AgentAdapterEvents> implements
22
23
  active(): string;
23
24
  select(id: string): void;
24
25
  messages(agentId?: string): readonly Message[];
26
+ attachmentLimits(): AttachmentLimits;
25
27
  send(agentId: string, input: string | Outgoing): Promise<void>;
26
28
  rewind(agentId: string, messageId: string): Promise<Outgoing | null>;
27
29
  stop(agentId?: string): void;
@@ -1,8 +1,17 @@
1
1
  import type { Attachment } from '@ai-ecoverse/slicc-spectrum/ui';
2
- import { type SendAttachment } from '../attachments.ts';
2
+ import { type AttachmentKind, type SendAttachment } from '../attachments.ts';
3
3
  import { type Shrink } from '../images/fit.ts';
4
4
  import type { ImageRef, StoredImage } from '../services.ts';
5
- export type Read = (url: string) => Promise<Uint8Array>;
5
+ export type Read = (url: string) => Promise<Blob>;
6
6
  export type Stored = (ref: ImageRef) => Promise<StoredImage>;
7
+ export type Stage = (body: Blob) => Promise<string>;
8
+ export type AttachmentLimits = Partial<Record<AttachmentKind | 'secret' | 'total', number>>;
9
+ export interface Stager {
10
+ stage: Stage;
11
+ clear(): Promise<void>;
12
+ }
7
13
  export declare const readUrl: Read;
8
- export declare function sendAttachments(attachments?: readonly Attachment[], read?: Read, fit?: Shrink, stored?: Stored): Promise<SendAttachment[]>;
14
+ export declare function limitsOf(staging: boolean): AttachmentLimits;
15
+ export declare function stagingDir(serverId: string, root?: () => Promise<FileSystemDirectoryHandle>): Promise<FileSystemDirectoryHandle | undefined>;
16
+ export declare function stager(dir: FileSystemDirectoryHandle): Stager;
17
+ export declare function sendAttachments(attachments?: readonly Attachment[], read?: Read, fit?: Shrink, stored?: Stored, stage?: Stage): Promise<SendAttachment[]>;
@@ -0,0 +1,13 @@
1
+ export declare const STAGED_MS: number;
2
+ export interface Staging {
3
+ take(id: string): Promise<Blob | undefined>;
4
+ drop(id: string): Promise<void>;
5
+ sweep(): Promise<void>;
6
+ close(): void;
7
+ }
8
+ export interface StagingOptions {
9
+ root?: () => Promise<FileSystemDirectoryHandle>;
10
+ maxAgeMs?: number;
11
+ now?: () => number;
12
+ }
13
+ export declare function workerStaging(serverId: string, options?: StagingOptions): Staging;
@@ -2,12 +2,14 @@ import type { Context } from '@earendil-works/chord';
2
2
  import type { Conversation, ModelRef } from '@earendil-works/pi-durable';
3
3
  import type { ExecutionEnv } from '@earendil-works/pi-durable/env';
4
4
  import type { Saver } from './attachments.ts';
5
+ import type { Staging } from './staging.ts';
5
6
  export interface Uploads {
6
7
  env(target: {
7
8
  conversationId: number;
8
9
  cwd?: string;
9
10
  }, context: Context): ExecutionEnv | undefined | Promise<ExecutionEnv | undefined>;
10
11
  sees(model: ModelRef | undefined): boolean;
12
+ staging?: Staging;
11
13
  }
12
14
  export declare const UPLOADS = "uploads";
13
15
  export declare function upload(env: ExecutionEnv, name: string, bytes: Uint8Array, context: Context): Promise<string>;
package/dist/uploads.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const UPLOADS = "uploads";
2
2
  function cleaned(name) {
3
- const clean = name.replace(/[/\\\0]/g, "_").replace(/^\.+/, "") || "attachment";
3
+ const clean = name.replace(/[/\\<>"\p{Cc}]/gu, "_").replace(/^\.+/, "") || "attachment";
4
4
  const dot = clean.lastIndexOf(".");
5
5
  return dot > 0 ? { stem: clean.slice(0, dot), ext: clean.slice(dot) } : { stem: clean, ext: "" };
6
6
  }
@@ -21,9 +21,11 @@ async function upload(env, name, bytes, context) {
21
21
  }
22
22
  async function saverFor(conversation, uploads, context) {
23
23
  if (!uploads) return { sees: true };
24
+ await uploads.staging?.sweep();
24
25
  const agent = await conversation.agent(context);
25
26
  return {
26
27
  sees: uploads.sees(agent.model),
28
+ ...uploads.staging ? { staging: uploads.staging } : {},
27
29
  async save(name, bytes) {
28
30
  const target = {
29
31
  conversationId: conversation.id,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/uploads.ts"],
4
- "sourcesContent": ["import type { Context } from '@earendil-works/chord';\nimport type { Conversation, ModelRef } from '@earendil-works/pi-durable';\nimport type { ExecutionEnv } from '@earendil-works/pi-durable/env';\nimport type { Saver } from './attachments.ts';\n\nexport interface Uploads {\n env(\n target: { conversationId: number; cwd?: string },\n context: Context\n ): ExecutionEnv | undefined | Promise<ExecutionEnv | undefined>;\n sees(model: ModelRef | undefined): boolean;\n}\n\nexport const UPLOADS = 'uploads';\n\nfunction cleaned(name: string): { stem: string; ext: string } {\n const clean = name.replace(/[/\\\\\\0]/g, '_').replace(/^\\.+/, '') || 'attachment';\n const dot = clean.lastIndexOf('.');\n return dot > 0 ? { stem: clean.slice(0, dot), ext: clean.slice(dot) } : { stem: clean, ext: '' };\n}\n\nfunction must(result: { ok: boolean; error?: { message: string } }, name: string): void {\n if (!result.ok) throw new Error(`Couldn't save ${name}: ${result.error?.message}`);\n}\n\nexport async function upload(\n env: ExecutionEnv,\n name: string,\n bytes: Uint8Array,\n context: Context\n): Promise<string> {\n const dir = `${env.cwd.replace(/\\/+$/, '')}/${UPLOADS}`;\n must(await env.createDir(dir, { recursive: true }, context), name);\n const { stem, ext } = cleaned(name);\n for (let n = 0; n < 100; n++) {\n const path = `${dir}/${n ? `${stem}-${n}${ext}` : `${stem}${ext}`}`;\n if ((await env.fileInfo(path, context)).ok) continue;\n must(await env.writeFile(path, bytes, context), name);\n return path;\n }\n throw new Error(`Couldn't find a free name for ${name} in ${dir}.`);\n}\n\nexport async function saverFor(\n conversation: Conversation,\n uploads: Uploads | undefined,\n context: Context\n): Promise<Saver> {\n if (!uploads) return { sees: true };\n const agent = await conversation.agent(context);\n return {\n sees: uploads.sees(agent.model),\n async save(name, bytes) {\n const target = {\n conversationId: conversation.id,\n ...(agent.cwd ? { cwd: agent.cwd } : {}),\n };\n const env = await uploads.env(target, context);\n if (!env) throw new Error(`This agent has no folder to save ${name} in.`);\n return upload(env, name, bytes, context);\n },\n };\n}\n"],
5
- "mappings": "AAaO,MAAM,UAAU;AAEvB,SAAS,QAAQ,MAA6C;AAC5D,QAAM,QAAQ,KAAK,QAAQ,YAAY,GAAG,EAAE,QAAQ,QAAQ,EAAE,KAAK;AACnE,QAAM,MAAM,MAAM,YAAY,GAAG;AACjC,SAAO,MAAM,IAAI,EAAE,MAAM,MAAM,MAAM,GAAG,GAAG,GAAG,KAAK,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,MAAM,OAAO,KAAK,GAAG;AACjG;AAEA,SAAS,KAAK,QAAsD,MAAoB;AACtF,MAAI,CAAC,OAAO,GAAI,OAAM,IAAI,MAAM,iBAAiB,IAAI,KAAK,OAAO,OAAO,OAAO,EAAE;AACnF;AAEA,eAAsB,OACpB,KACA,MACA,OACA,SACiB;AACjB,QAAM,MAAM,GAAG,IAAI,IAAI,QAAQ,QAAQ,EAAE,CAAC,IAAI,OAAO;AACrD,OAAK,MAAM,IAAI,UAAU,KAAK,EAAE,WAAW,KAAK,GAAG,OAAO,GAAG,IAAI;AACjE,QAAM,EAAE,MAAM,IAAI,IAAI,QAAQ,IAAI;AAClC,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC5B,UAAM,OAAO,GAAG,GAAG,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,EAAE;AACjE,SAAK,MAAM,IAAI,SAAS,MAAM,OAAO,GAAG,GAAI;AAC5C,SAAK,MAAM,IAAI,UAAU,MAAM,OAAO,OAAO,GAAG,IAAI;AACpD,WAAO;AAAA,EACT;AACA,QAAM,IAAI,MAAM,iCAAiC,IAAI,OAAO,GAAG,GAAG;AACpE;AAEA,eAAsB,SACpB,cACA,SACA,SACgB;AAChB,MAAI,CAAC,QAAS,QAAO,EAAE,MAAM,KAAK;AAClC,QAAM,QAAQ,MAAM,aAAa,MAAM,OAAO;AAC9C,SAAO;AAAA,IACL,MAAM,QAAQ,KAAK,MAAM,KAAK;AAAA,IAC9B,MAAM,KAAK,MAAM,OAAO;AACtB,YAAM,SAAS;AAAA,QACb,gBAAgB,aAAa;AAAA,QAC7B,GAAI,MAAM,MAAM,EAAE,KAAK,MAAM,IAAI,IAAI,CAAC;AAAA,MACxC;AACA,YAAM,MAAM,MAAM,QAAQ,IAAI,QAAQ,OAAO;AAC7C,UAAI,CAAC,IAAK,OAAM,IAAI,MAAM,oCAAoC,IAAI,MAAM;AACxE,aAAO,OAAO,KAAK,MAAM,OAAO,OAAO;AAAA,IACzC;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import type { Context } from '@earendil-works/chord';\nimport type { Conversation, ModelRef } from '@earendil-works/pi-durable';\nimport type { ExecutionEnv } from '@earendil-works/pi-durable/env';\nimport type { Saver } from './attachments.ts';\nimport type { Staging } from './staging.ts';\n\nexport interface Uploads {\n env(\n target: { conversationId: number; cwd?: string },\n context: Context\n ): ExecutionEnv | undefined | Promise<ExecutionEnv | undefined>;\n sees(model: ModelRef | undefined): boolean;\n staging?: Staging;\n}\n\nexport const UPLOADS = 'uploads';\n\nfunction cleaned(name: string): { stem: string; ext: string } {\n const clean = name.replace(/[/\\\\<>\"\\p{Cc}]/gu, '_').replace(/^\\.+/, '') || 'attachment';\n const dot = clean.lastIndexOf('.');\n return dot > 0 ? { stem: clean.slice(0, dot), ext: clean.slice(dot) } : { stem: clean, ext: '' };\n}\n\nfunction must(result: { ok: boolean; error?: { message: string } }, name: string): void {\n if (!result.ok) throw new Error(`Couldn't save ${name}: ${result.error?.message}`);\n}\n\nexport async function upload(\n env: ExecutionEnv,\n name: string,\n bytes: Uint8Array,\n context: Context\n): Promise<string> {\n const dir = `${env.cwd.replace(/\\/+$/, '')}/${UPLOADS}`;\n must(await env.createDir(dir, { recursive: true }, context), name);\n const { stem, ext } = cleaned(name);\n for (let n = 0; n < 100; n++) {\n const path = `${dir}/${n ? `${stem}-${n}${ext}` : `${stem}${ext}`}`;\n if ((await env.fileInfo(path, context)).ok) continue;\n must(await env.writeFile(path, bytes, context), name);\n return path;\n }\n throw new Error(`Couldn't find a free name for ${name} in ${dir}.`);\n}\n\nexport async function saverFor(\n conversation: Conversation,\n uploads: Uploads | undefined,\n context: Context\n): Promise<Saver> {\n if (!uploads) return { sees: true };\n await uploads.staging?.sweep();\n const agent = await conversation.agent(context);\n return {\n sees: uploads.sees(agent.model),\n ...(uploads.staging ? { staging: uploads.staging } : {}),\n async save(name, bytes) {\n const target = {\n conversationId: conversation.id,\n ...(agent.cwd ? { cwd: agent.cwd } : {}),\n };\n const env = await uploads.env(target, context);\n if (!env) throw new Error(`This agent has no folder to save ${name} in.`);\n return upload(env, name, bytes, context);\n },\n };\n}\n"],
5
+ "mappings": "AAeO,MAAM,UAAU;AAEvB,SAAS,QAAQ,MAA6C;AAC5D,QAAM,QAAQ,KAAK,QAAQ,oBAAoB,GAAG,EAAE,QAAQ,QAAQ,EAAE,KAAK;AAC3E,QAAM,MAAM,MAAM,YAAY,GAAG;AACjC,SAAO,MAAM,IAAI,EAAE,MAAM,MAAM,MAAM,GAAG,GAAG,GAAG,KAAK,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,MAAM,OAAO,KAAK,GAAG;AACjG;AAEA,SAAS,KAAK,QAAsD,MAAoB;AACtF,MAAI,CAAC,OAAO,GAAI,OAAM,IAAI,MAAM,iBAAiB,IAAI,KAAK,OAAO,OAAO,OAAO,EAAE;AACnF;AAEA,eAAsB,OACpB,KACA,MACA,OACA,SACiB;AACjB,QAAM,MAAM,GAAG,IAAI,IAAI,QAAQ,QAAQ,EAAE,CAAC,IAAI,OAAO;AACrD,OAAK,MAAM,IAAI,UAAU,KAAK,EAAE,WAAW,KAAK,GAAG,OAAO,GAAG,IAAI;AACjE,QAAM,EAAE,MAAM,IAAI,IAAI,QAAQ,IAAI;AAClC,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK;AAC5B,UAAM,OAAO,GAAG,GAAG,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,EAAE;AACjE,SAAK,MAAM,IAAI,SAAS,MAAM,OAAO,GAAG,GAAI;AAC5C,SAAK,MAAM,IAAI,UAAU,MAAM,OAAO,OAAO,GAAG,IAAI;AACpD,WAAO;AAAA,EACT;AACA,QAAM,IAAI,MAAM,iCAAiC,IAAI,OAAO,GAAG,GAAG;AACpE;AAEA,eAAsB,SACpB,cACA,SACA,SACgB;AAChB,MAAI,CAAC,QAAS,QAAO,EAAE,MAAM,KAAK;AAClC,QAAM,QAAQ,SAAS,MAAM;AAC7B,QAAM,QAAQ,MAAM,aAAa,MAAM,OAAO;AAC9C,SAAO;AAAA,IACL,MAAM,QAAQ,KAAK,MAAM,KAAK;AAAA,IAC9B,GAAI,QAAQ,UAAU,EAAE,SAAS,QAAQ,QAAQ,IAAI,CAAC;AAAA,IACtD,MAAM,KAAK,MAAM,OAAO;AACtB,YAAM,SAAS;AAAA,QACb,gBAAgB,aAAa;AAAA,QAC7B,GAAI,MAAM,MAAM,EAAE,KAAK,MAAM,IAAI,IAAI,CAAC;AAAA,MACxC;AACA,YAAM,MAAM,MAAM,QAAQ,IAAI,QAAQ,OAAO;AAC7C,UAAI,CAAC,IAAK,OAAM,IAAI,MAAM,oCAAoC,IAAI,MAAM;AACxE,aAAO,OAAO,KAAK,MAAM,OAAO,OAAO;AAAA,IACzC;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-agent",
3
- "version": "7.25.1",
3
+ "version": "7.26.0",
4
4
  "description": "SLICC's agent core on pi durable: an agent worker, session storage, remoting and pi extensions",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",